Decompiled source of LethalGoHome v1.20.35

LethalGoHome.dll

Decompiled an hour 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.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalGoHome
{
	internal sealed class AdaptiveBulbHud : MonoBehaviour
	{
		private RectTransform rect;

		private RectTransform parent;

		private Canvas canvas;

		private int slot;

		private float nextCheck;

		private Vector2 current;

		private readonly List<Graphic> graphics = new List<Graphic>();

		internal void Initialize()
		{
			//IL_0093: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			ref RectTransform reference = ref rect;
			Transform transform = ((Component)this).transform;
			reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			ref RectTransform reference2 = ref parent;
			Transform obj = ((Component)this).transform.parent;
			reference2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			canvas = ((Component)this).GetComponentInParent<Canvas>();
			if ((Object)(object)canvas != (Object)null)
			{
				canvas = canvas.rootCanvas;
			}
			if ((Object)(object)rect == (Object)null || (Object)(object)parent == (Object)null)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			RectTransform obj2 = rect;
			RectTransform obj3 = rect;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0f);
			obj3.anchorMax = val;
			obj2.anchorMin = val;
			rect.pivot = new Vector2(0.5f, 0f);
			current = Position(0);
			rect.anchoredPosition = current;
			nextCheck = Time.unscaledTime + 0.2f;
		}

		private Vector2 Position(int index)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			Rect val = rect.rect;
			float num = ((Rect)(ref val)).width * 0.5f + 20f;
			val = parent.rect;
			float num2 = ((Rect)(ref val)).width * 0.5f - 44f;
			val = rect.rect;
			float num3 = Mathf.Max(num, num2 - ((Rect)(ref val)).width * 0.5f);
			val = parent.rect;
			float height = ((Rect)(ref val)).height;
			val = rect.rect;
			float num4 = Mathf.Max(34f, height - ((Rect)(ref val)).height - 30f);
			float num5 = ((index % 2 == 0) ? num3 : (0f - num3));
			float num6 = index / 2;
			val = rect.rect;
			return new Vector2(num5, Mathf.Min(34f + num6 * (((Rect)(ref val)).height + 28f), num4));
		}

		private Rect ScreenRect(Vector2 pos, Camera cam)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			Rect val = parent.rect;
			float num = ((Rect)(ref val)).center.x + pos.x;
			val = parent.rect;
			float num2 = ((Rect)(ref val)).yMin + pos.y;
			RectTransform obj = parent;
			val = rect.rect;
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(cam, ((Transform)obj).TransformPoint(new Vector3(num - ((Rect)(ref val)).width * 0.5f, num2, 0f)));
			RectTransform obj2 = parent;
			val = rect.rect;
			float num3 = num + ((Rect)(ref val)).width * 0.5f;
			val = rect.rect;
			Vector2 val3 = RectTransformUtility.WorldToScreenPoint(cam, ((Transform)obj2).TransformPoint(new Vector3(num3, num2 + ((Rect)(ref val)).height, 0f)));
			return Rect.MinMaxRect(Mathf.Min(val2.x, val3.x), Mathf.Min(val2.y, val3.y), Mathf.Max(val2.x, val3.x), Mathf.Max(val2.y, val3.y));
		}

		private void Update()
		{
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Invalid comparison between Unknown and I4
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rect == (Object)null || (Object)(object)parent == (Object)null)
			{
				return;
			}
			if (Time.unscaledTime >= nextCheck)
			{
				nextCheck = Time.unscaledTime + 1f;
				Camera cam = (((Object)(object)canvas != (Object)null && (int)canvas.renderMode != 0) ? canvas.worldCamera : null);
				Rect[] array = (Rect[])(object)new Rect[6];
				float[] array2 = new float[6];
				for (int i = 0; i < 6; i++)
				{
					array[i] = ScreenRect(Position(i), cam);
					array2[i] = (float)(i / 2) * 0.015f;
				}
				List<Graphic> list = HudGraphicsCache.Graphics;
				Vector3[] array3 = (Vector3[])(object)new Vector3[4];
				float num = Mathf.Max(1f, (float)(Screen.width * Screen.height));
				foreach (Graphic item in list)
				{
					if ((Object)(object)item == (Object)null || !((Behaviour)item).enabled || !((Component)item).gameObject.activeInHierarchy || ((Component)item).transform.IsChildOf(((Component)this).transform) || (Object)(object)item.canvas == (Object)null || !((Behaviour)item.canvas).isActiveAndEnabled || (int)item.canvas.rootCanvas.renderMode == 2)
					{
						continue;
					}
					TMP_Text val2 = (TMP_Text)(object)((item is TMP_Text) ? item : null);
					if (val2 != null && string.IsNullOrWhiteSpace(val2.text))
					{
						continue;
					}
					float num2 = item.color.a * item.canvasRenderer.GetAlpha();
					num2 *= HudGraphicsCache.GroupAlpha(item);
					if (num2 < 0.08f || item.canvasRenderer.cull)
					{
						continue;
					}
					Canvas rootCanvas = item.canvas.rootCanvas;
					Camera obj = (((int)rootCanvas.renderMode != 0) ? rootCanvas.worldCamera : null);
					item.rectTransform.GetWorldCorners(array3);
					Vector2 val3 = RectTransformUtility.WorldToScreenPoint(obj, array3[0]);
					Vector2 val4 = RectTransformUtility.WorldToScreenPoint(obj, array3[2]);
					Rect val5 = Rect.MinMaxRect(Mathf.Min(val3.x, val4.x), Mathf.Min(val3.y, val4.y), Mathf.Max(val3.x, val4.x), Mathf.Max(val3.y, val4.y));
					if (!(((Rect)(ref val5)).width * ((Rect)(ref val5)).height > num * 0.4f))
					{
						for (int j = 0; j < 6; j++)
						{
							Rect val6 = array[j];
							float num3 = Mathf.Max(0f, Mathf.Min(((Rect)(ref val6)).xMax, ((Rect)(ref val5)).xMax) - Mathf.Max(((Rect)(ref val6)).xMin, ((Rect)(ref val5)).xMin));
							float num4 = Mathf.Max(0f, Mathf.Min(((Rect)(ref val6)).yMax, ((Rect)(ref val5)).yMax) - Mathf.Max(((Rect)(ref val6)).yMin, ((Rect)(ref val5)).yMin));
							array2[j] += num2 * num3 * num4 / Mathf.Max(1f, ((Rect)(ref val6)).width * ((Rect)(ref val6)).height);
						}
					}
				}
				slot = HudPlacementRules.Pick(array2, slot, 0.005f);
			}
			current = Vector2.Lerp(current, Position(slot), 1f - Mathf.Exp(-8f * Time.unscaledDeltaTime));
			rect.anchoredPosition = current;
		}
	}
	public sealed class BrassItem : GrabbableObject
	{
		public string ModelName;

		public override void Start()
		{
			GameVisuals.TryBrass((GrabbableObject)(object)this, ModelName);
			((GrabbableObject)this).Start();
		}
	}
	internal static class BrassPrefab
	{
		public static void CreateAll()
		{
			Create("brass_small", "Small fanfare horn", 47193);
			Create("brass_tuba", "Fanfare tuba horn", 47194);
			Create("brass_curled", "Curled fanfare horn", 47195);
			Create("wind_straight", "Fanfare wind instrument", 47196);
		}

		internal static void Create(string modelName, string title, int id, int rarity = -1)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_019d: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: 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_0270: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(Path.Combine(Plugin.PluginDir, "GameAssets", modelName + ".obj")))
			{
				Plugin.Log.LogWarning((object)"Brass assets not found; skipping scrap registration.");
				return;
			}
			GameObject val = NetworkPrefabs.CreateNetworkPrefab("LethalGoHome" + modelName);
			val.layer = 6;
			CartPrefab.TrySetTag(val, "PhysicsProp");
			NetworkObject component = val.GetComponent<NetworkObject>();
			component.AutoObjectParentSync = false;
			component.DontDestroyWithOwner = true;
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 1f;
			obj.maxDistance = 20f;
			obj.dopplerLevel = 0f;
			bool flag = modelName == "juice_pouch";
			BoxCollider obj2 = val.AddComponent<BoxCollider>();
			obj2.center = Vector3.zero;
			obj2.size = (Vector3)(flag ? new Vector3(0.25f, 0.36f, 0.2f) : (Vector3.one * 0.65f));
			Item val2 = ScriptableObject.CreateInstance<Item>();
			((Object)val2).name = "LethalGoHome" + modelName + "Item";
			val2.itemName = title;
			val2.itemId = id;
			val2.isScrap = true;
			val2.minValue = 45;
			val2.maxValue = 115;
			val2.weight = 1.15f;
			val2.twoHanded = false;
			val2.twoHandedAnimation = false;
			val2.grabAnim = "HoldItem";
			val2.itemSpawnsOnGround = true;
			val2.syncGrabFunction = true;
			val2.syncDiscardFunction = true;
			val2.canBeGrabbedBeforeGameStart = true;
			val2.allowDroppingAheadOfPlayer = true;
			val2.verticalOffset = (flag ? 0.18f : 0.33f);
			val2.floorYOffset = 0;
			val2.highestSalePercentage = 80;
			val2.restingRotation = Vector3.zero;
			val2.rotationOffset = Vector3.zero;
			val2.positionOffset = Vector3.zero;
			val2.meshVariants = (Mesh[])(object)new Mesh[0];
			val2.materialVariants = (Material[])(object)new Material[0];
			val2.clinkAudios = (AudioClip[])(object)new AudioClip[0];
			val2.spawnPositionTypes = new List<ItemGroup>();
			val2.toolTips = new string[0];
			val2.itemIcon = (flag ? CartIcon.CreateJuicePouch() : CartIcon.CreateBrass());
			val2.spawnPrefab = val;
			BrassItem brassItem = val.AddComponent<BrassItem>();
			brassItem.ModelName = modelName;
			((GrabbableObject)brassItem).itemProperties = val2;
			((GrabbableObject)brassItem).grabbable = true;
			((GrabbableObject)brassItem).grabbableToEnemies = true;
			GameObject val3 = new GameObject("ScanNode");
			val3.transform.SetParent(val.transform, false);
			val3.layer = 22;
			BoxCollider obj3 = val3.AddComponent<BoxCollider>();
			((Collider)obj3).isTrigger = true;
			obj3.size = Vector3.one * 0.5f;
			ScanNodeProperties obj4 = val3.AddComponent<ScanNodeProperties>();
			obj4.headerText = title;
			obj4.subText = "Value: $0";
			obj4.nodeType = 2;
			obj4.minRange = 1;
			obj4.maxRange = 13;
			obj4.requiresLineOfSight = true;
			obj4.creatureScanID = -1;
			Items.RegisterScrap(val2, (rarity >= 0) ? rarity : CartConfig.BrassRarity.Value, (LevelTypes)(-1));
		}
	}
	[HarmonyPatch]
	internal sealed class BulbFailure : MonoBehaviour
	{
		private sealed class PendingDeath
		{
			internal PlayerControllerB Player;

			internal Vector3 Position;

			internal float Yaw;

			internal bool Inside;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnRequest;

			public static HandleNamedMessageDelegate <1>__OnEffect;
		}

		private const string RequestMessage = "LethalGoHome_BulbFailureRequest_v1";

		private const string EffectMessage = "LethalGoHome_BulbFailureEffect_v1";

		private const byte Begin = 0;

		private const byte Complete = 1;

		private const byte Configure = 2;

		private const float SequenceSeconds = 4.25f;

		private static BulbFailure instance;

		private static bool registered;

		private static bool pendingLocal;

		private static bool bypassKill;

		private static AudioClip failureAudio;

		private static readonly Dictionary<ulong, PendingDeath> pending = new Dictionary<ulong, PendingDeath>();

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

		internal static void Create(Plugin plugin)
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = ((Component)plugin).gameObject.AddComponent<BulbFailure>();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void Register()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			registered = false;
			pendingLocal = (bypassKill = false);
			pending.Clear();
			spawned.Clear();
			if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null)
			{
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				object obj = <>O.<0>__OnRequest;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnRequest;
					<>O.<0>__OnRequest = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("LethalGoHome_BulbFailureRequest_v1", (HandleNamedMessageDelegate)obj);
				CustomMessagingManager customMessagingManager2 = singleton.CustomMessagingManager;
				object obj2 = <>O.<1>__OnEffect;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnEffect;
					<>O.<1>__OnEffect = val2;
					obj2 = (object)val2;
				}
				customMessagingManager2.RegisterNamedMessageHandler("LethalGoHome_BulbFailureEffect_v1", (HandleNamedMessageDelegate)obj2);
				registered = true;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		[HarmonyPrefix]
		private static void ProtectDuringSequence(PlayerControllerB __instance, ref int damageNumber)
		{
			if (pendingLocal && ((NetworkBehaviour)__instance).IsOwner)
			{
				damageNumber = 0;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPrefix]
		private static bool OnKill(PlayerControllerB __instance, Vector3 bodyVelocity, bool spawnBody, CauseOfDeath causeOfDeath, int deathAnimation, Vector3 positionOffset, bool setOverrideDropItems)
		{
			//IL_006f: 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)
			if (bypassKill || !((NetworkBehaviour)__instance).IsOwner || __instance.isPlayerDead)
			{
				return true;
			}
			if (pendingLocal)
			{
				return false;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if (!registered || (Object)(object)instance == (Object)null || (Object)(object)singleton == (Object)null || !singleton.IsListening || !BulbHealth.HealthIsExhausted(__instance))
			{
				return true;
			}
			pendingLocal = true;
			__instance.health = 1;
			((MonoBehaviour)instance).StartCoroutine(instance.FinishDeath(__instance, bodyVelocity, causeOfDeath, deathAnimation, positionOffset, setOverrideDropItems));
			Send(0);
			return false;
		}

		private IEnumerator FinishDeath(PlayerControllerB player, Vector3 velocity, CauseOfDeath cause, int animation, Vector3 offset, bool overrideDrop)
		{
			//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)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			bool oldDisabled = player.disableMoveInput;
			player.disableMoveInput = true;
			yield return (object)new WaitForSecondsRealtime(4.25f);
			if ((Object)(object)player != (Object)null)
			{
				player.disableMoveInput = oldDisabled;
				if (!player.isPlayerDead && ((NetworkBehaviour)player).IsOwner)
				{
					bypassKill = true;
					try
					{
						player.KillPlayer(velocity, false, cause, animation, offset, overrideDrop);
					}
					finally
					{
						bypassKill = false;
					}
					if (player.isPlayerDead)
					{
						Send(1);
					}
				}
			}
			pendingLocal = false;
		}

		private unsafe static void Send(byte op)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!registered || (Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref op, default(ForPrimitives));
				if (singleton.IsServer)
				{
					FastBufferReader r = default(FastBufferReader);
					((FastBufferReader)(ref r))..ctor(val, (Allocator)2, -1, 0, (Allocator)2);
					try
					{
						OnRequest(singleton.LocalClientId, r);
						return;
					}
					finally
					{
						((IDisposable)(*(FastBufferReader*)(&r))/*cast due to .constrained prefix*/).Dispose();
					}
				}
				singleton.CustomMessagingManager.SendNamedMessage("LethalGoHome_BulbFailureRequest_v1", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static PlayerControllerB FindLivePlayer(ulong sender)
		{
			StartOfRound val = StartOfRound.Instance;
			if ((Object)(object)val == (Object)null || val.allPlayerScripts == null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = val.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if ((Object)(object)val2 != (Object)null && val2.isPlayerControlled && val2.actualClientId == sender)
				{
					return val2;
				}
			}
			return null;
		}

		private static int IndexOf(PlayerControllerB p)
		{
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array == null)
			{
				return -1;
			}
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i] == (Object)(object)p)
				{
					return i;
				}
			}
			return -1;
		}

		private static void OnRequest(ulong sender, FastBufferReader r)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || (Object)(object)instance == (Object)null)
			{
				return;
			}
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			switch (b)
			{
			case 0:
			{
				PlayerControllerB val = FindLivePlayer(sender);
				if (!((Object)(object)val == (Object)null) && BulbHealth.ServerHasUpgrade(val) && !pending.ContainsKey(sender))
				{
					PendingDeath pendingDeath = new PendingDeath
					{
						Player = val,
						Position = ((Component)val).transform.position,
						Yaw = ((Component)val).transform.eulerAngles.y,
						Inside = val.isInsideFactory
					};
					pending[sender] = pendingDeath;
					spawned.Remove(sender);
					Broadcast(0, IndexOf(val), 0uL, pendingDeath.Inside);
					((MonoBehaviour)instance).StartCoroutine(instance.ExpirePending(sender, pendingDeath));
				}
				break;
			}
			case 1:
			{
				if (pending.TryGetValue(sender, out var value) && !spawned.Contains(sender))
				{
					spawned.Add(sender);
					((MonoBehaviour)instance).StartCoroutine(instance.SpawnAfterDeath(sender, value));
				}
				break;
			}
			}
		}

		private IEnumerator ExpirePending(ulong sender, PendingDeath record)
		{
			yield return (object)new WaitForSecondsRealtime(15f);
			if (pending.TryGetValue(sender, out var value) && value == record)
			{
				pending.Remove(sender);
				spawned.Remove(sender);
			}
		}

		private unsafe static void Broadcast(byte op, int playerIndex, ulong enemyId, bool inside)
		{
			//IL_0029: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref op, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref playerIndex, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref enemyId, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref inside, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessageToAll("LethalGoHome_BulbFailureEffect_v1", val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnEffect(ulong sender, FastBufferReader r)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (sender != 0L || (Object)(object)instance == (Object)null)
			{
				return;
			}
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong enemyId = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
			bool inside = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref inside, default(ForPrimitives));
			StartOfRound val = StartOfRound.Instance;
			if ((Object)(object)val == (Object)null || val.allPlayerScripts == null || num < 0 || num >= val.allPlayerScripts.Length)
			{
				return;
			}
			PlayerControllerB val2 = val.allPlayerScripts[num];
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			switch (b)
			{
			case 0:
				if ((Object)(object)failureAudio == (Object)null)
				{
					failureAudio = CartAudio.TryLoadWav("gameover");
				}
				if ((Object)(object)failureAudio != (Object)null)
				{
					AudioSource.PlayClipAtPoint(failureAudio, ((Component)val2).transform.position, 0.8f);
				}
				(((Component)val2).gameObject.GetComponent<BulbFailurePose>() ?? ((Component)val2).gameObject.AddComponent<BulbFailurePose>()).Play(4.25f);
				if (((NetworkBehaviour)val2).IsOwner)
				{
					BulbDeathScreen.Show(val2, 4.25f);
				}
				break;
			case 2:
				((MonoBehaviour)instance).StartCoroutine(instance.ConfigureClient(enemyId, val2, inside));
				break;
			}
		}

		private static EnemyType MaskedType()
		{
			StartOfRound val = StartOfRound.Instance;
			if ((Object)(object)val != (Object)null && val.levels != null)
			{
				SelectableLevel[] levels = val.levels;
				foreach (SelectableLevel val2 in levels)
				{
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val2.Enemies, val2.OutsideEnemies, val2.DaytimeEnemies };
					foreach (List<SpawnableEnemyWithRarity> list in array)
					{
						if (list == null)
						{
							continue;
						}
						foreach (SpawnableEnemyWithRarity item in list)
						{
							if (item != null && (Object)(object)item.enemyType != (Object)null && (Object)(object)item.enemyType.enemyPrefab != (Object)null && (Object)(object)item.enemyType.enemyPrefab.GetComponent<MaskedPlayerEnemy>() != (Object)null)
							{
								return item.enemyType;
							}
						}
					}
				}
			}
			EnemyType[] array2 = Resources.FindObjectsOfTypeAll<EnemyType>();
			foreach (EnemyType val3 in array2)
			{
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3.enemyPrefab != (Object)null && (Object)(object)val3.enemyPrefab.GetComponent<MaskedPlayerEnemy>() != (Object)null)
				{
					return val3;
				}
			}
			return null;
		}

		private IEnumerator SpawnAfterDeath(ulong sender, PendingDeath record)
		{
			PlayerControllerB player = record.Player;
			float deadline = Time.realtimeSinceStartup + 4f;
			while ((Object)(object)player != (Object)null && !player.isPlayerDead && Time.realtimeSinceStartup < deadline)
			{
				yield return null;
			}
			if ((Object)(object)player == (Object)null || !player.isPlayerDead || (Object)(object)RoundManager.Instance == (Object)null)
			{
				pending.Remove(sender);
				yield break;
			}
			EnemyType val = MaskedType();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Bulb failure: masked enemy prefab is unavailable; player died normally.");
				pending.Remove(sender);
				yield break;
			}
			Vector3 position = record.Position;
			NavMeshHit val2 = default(NavMeshHit);
			if (NavMesh.SamplePosition(position, ref val2, 4f, -1))
			{
				position = ((NavMeshHit)(ref val2)).position;
				NetworkObject val3 = null;
				try
				{
					NetworkObjectReference val4 = RoundManager.Instance.SpawnEnemyGameObject(position, record.Yaw, -1, val);
					((NetworkObjectReference)(ref val4)).TryGet(ref val3, (NetworkManager)null);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Bulb failure: could not spawn masked enemy: " + ex.Message));
				}
				if ((Object)(object)val3 == (Object)null)
				{
					pending.Remove(sender);
					yield break;
				}
				MaskedPlayerEnemy masked = ((Component)val3).GetComponent<MaskedPlayerEnemy>() ?? ((Component)val3).GetComponentInParent<MaskedPlayerEnemy>();
				if ((Object)(object)masked == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Bulb failure: spawned enemy has no masked AI.");
					pending.Remove(sender);
					yield break;
				}
				masked.allowSpawningWithoutPlayer = true;
				masked.mimickingPlayer = player;
				((EnemyAI)masked).SetEnemyOutside(!record.Inside);
				masked.SetSuit(player.currentSuitID);
				masked.SetVisibilityOfMaskedEnemy();
				((Component)masked).gameObject.AddComponent<AngryBulbMimic>();
				Broadcast(2, IndexOf(player), val3.NetworkObjectId, record.Inside);
				yield return (object)new WaitForSeconds(0.75f);
				try
				{
					MonoBehaviour[] components = ((Component)masked).GetComponents<MonoBehaviour>();
					foreach (MonoBehaviour val5 in components)
					{
						if (!((Object)(object)val5 == (Object)null) && !(((object)val5).GetType().FullName != "Mirage.Unity.MimicPlayer+MimicPlayer"))
						{
							MethodInfo method = ((object)val5).GetType().GetMethod("MimicPlayer", BindingFlags.Instance | BindingFlags.Public);
							if (method != null)
							{
								method.Invoke(val5, new object[1] { IndexOf(player) });
								break;
							}
						}
					}
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogWarning((object)("Bulb failure: Mirage appearance/voice setup failed: " + ex2.Message));
				}
				pending.Remove(sender);
			}
			else
			{
				Plugin.Log.LogWarning((object)"Bulb failure: no nearby navigation mesh; player died normally.");
				pending.Remove(sender);
			}
		}

		private IEnumerator ConfigureClient(ulong enemyId, PlayerControllerB player, bool inside)
		{
			float deadline = Time.realtimeSinceStartup + 8f;
			NetworkObject net = null;
			while (Time.realtimeSinceStartup < deadline)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(enemyId, out net) && (Object)(object)net != (Object)null)
				{
					break;
				}
				yield return null;
			}
			if (!((Object)(object)net == (Object)null) && !((Object)(object)player == (Object)null))
			{
				MaskedPlayerEnemy val = ((Component)net).GetComponent<MaskedPlayerEnemy>() ?? ((Component)net).GetComponentInParent<MaskedPlayerEnemy>();
				if (!((Object)(object)val == (Object)null))
				{
					val.allowSpawningWithoutPlayer = true;
					val.mimickingPlayer = player;
					((EnemyAI)val).SetEnemyOutside(!inside);
					val.SetSuit(player.currentSuitID);
					val.SetVisibilityOfMaskedEnemy();
				}
			}
		}
	}
	[DefaultExecutionOrder(31000)]
	internal sealed class BulbFailurePose : MonoBehaviour
	{
		private PlayerControllerB player;

		private Transform spine;

		private Transform head;

		private Transform left;

		private Transform right;

		private float endTime;

		private float duration;

		internal void Play(float seconds)
		{
			player = ((Component)this).GetComponent<PlayerControllerB>();
			duration = seconds;
			endTime = Time.realtimeSinceStartup + seconds;
			if ((Object)(object)player == (Object)null || (Object)(object)player.thisPlayerModel == (Object)null)
			{
				return;
			}
			Transform[] bones = player.thisPlayerModel.bones;
			foreach (Transform val in bones)
			{
				if (!((Object)(object)val == (Object)null))
				{
					switch (((Object)val).name)
					{
					case "spine.001":
						spine = val;
						break;
					case "spine.004":
						head = val;
						break;
					case "arm.L_upper":
						left = val;
						break;
					case "arm.R_upper":
						right = val;
						break;
					}
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || Time.realtimeSinceStartup >= endTime || player.isPlayerDead)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			float num = duration - (endTime - Time.realtimeSinceStartup);
			float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 0.6f));
			float num3 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((num - 2.4f) / 0.8f));
			Transform val = (((Object)(object)player.thisPlayerBody != (Object)null) ? player.thisPlayerBody : ((Component)player).transform);
			float num4 = num2 * (1f - 0.5f * num3);
			float num5 = (Mathf.Sin(num * 53f) + 0.6f * Mathf.Sin(num * 31f + 1.3f)) * 3.5f * num4;
			if ((Object)(object)spine != (Object)null)
			{
				spine.rotation = Quaternion.AngleAxis(-18f * num2 + 32f * num3 + num5, val.right) * Quaternion.AngleAxis(num5 * 0.8f, val.forward) * spine.rotation;
			}
			if ((Object)(object)head != (Object)null)
			{
				head.rotation = Quaternion.AngleAxis(-16f * num2 + 30f * num3 - num5 * 1.5f, val.right) * Quaternion.AngleAxis(num5 * 1.2f, val.up) * head.rotation;
			}
			if ((Object)(object)left != (Object)null)
			{
				left.rotation = Quaternion.AngleAxis(-70f * num2 + num5 * 2f, val.forward) * left.rotation;
			}
			if ((Object)(object)right != (Object)null)
			{
				right.rotation = Quaternion.AngleAxis(70f * num2 - num5 * 2f, val.forward) * right.rotation;
			}
		}
	}
	internal sealed class BulbFailureHud : MonoBehaviour
	{
		private RectTransform rect;

		private Image icon;

		private float started;

		private float length;

		internal static void Show(float seconds)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_009d: 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_00a6: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			HUDManager instance = HUDManager.Instance;
			Sprite originalBulbGlyph = BulbHealth.OriginalBulbGlyph;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.HUDContainer == (Object)null) && !((Object)(object)originalBulbGlyph == (Object)null))
			{
				GameObject val = new GameObject("OriginalBulbFailure", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(instance.HUDContainer.transform, false);
				BulbFailureHud bulbFailureHud = val.AddComponent<BulbFailureHud>();
				bulbFailureHud.rect = (RectTransform)val.transform;
				RectTransform obj = bulbFailureHud.rect;
				RectTransform obj2 = bulbFailureHud.rect;
				RectTransform obj3 = bulbFailureHud.rect;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 0.5f);
				obj3.pivot = val2;
				Vector2 anchorMin = (obj2.anchorMax = val2);
				obj.anchorMin = anchorMin;
				bulbFailureHud.rect.sizeDelta = new Vector2(100f, 116f);
				bulbFailureHud.rect.anchoredPosition = new Vector2(0f, 80f);
				bulbFailureHud.icon = val.AddComponent<Image>();
				bulbFailureHud.icon.sprite = originalBulbGlyph;
				bulbFailureHud.icon.preserveAspect = true;
				((Graphic)bulbFailureHud.icon).raycastTarget = false;
				bulbFailureHud.started = Time.realtimeSinceStartup;
				bulbFailureHud.length = seconds;
			}
		}

		private void Update()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.realtimeSinceStartup - started;
			if (num >= length)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float num2 = Mathf.Sin(num * 27f) * Mathf.Clamp01(num / 0.7f) * 3f;
			rect.anchoredPosition = new Vector2(num2, 80f);
			float num3 = 1f + 0.13f * Mathf.Sin(num * 13f);
			((Transform)rect).localScale = Vector3.one * num3;
			float num4 = ((num > length - 0.8f) ? Mathf.Clamp01((length - num) / 0.8f) : 1f);
			if (num > 2.4f && Mathf.Sin(num * 31f) < 0f)
			{
				num4 *= 0.28f;
			}
			((Graphic)icon).color = new Color(1f, 0.48f, 0.1f, num4);
		}
	}
	[DefaultExecutionOrder(31001)]
	internal sealed class AngryBulbMimic : MonoBehaviour
	{
		private MaskedPlayerEnemy masked;

		private float nextTarget;

		private void Awake()
		{
			masked = ((Component)this).GetComponent<MaskedPlayerEnemy>();
		}

		private void LateUpdate()
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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)
			if ((Object)(object)masked == (Object)null || !((NetworkBehaviour)masked).IsServer || ((EnemyAI)masked).isEnemyDead || ((EnemyAI)masked).inSpecialAnimation)
			{
				return;
			}
			if ((Object)(object)((EnemyAI)masked).agent != (Object)null && ((EnemyAI)masked).agent.isOnNavMesh && ((EnemyAI)masked).stunNormalizedTimer < 0f)
			{
				((EnemyAI)masked).agent.speed = Mathf.Max(((EnemyAI)masked).agent.speed, 5.5f);
			}
			if (Time.time < nextTarget)
			{
				return;
			}
			nextTarget = Time.time + 0.4f;
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null)
			{
				return;
			}
			PlayerControllerB val = null;
			float num = float.MaxValue;
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if (!((Object)(object)val2 == (Object)null) && val2.isPlayerControlled && !val2.isPlayerDead && val2.isInsideFactory != ((EnemyAI)masked).isOutside)
				{
					Vector3 val3 = ((Component)val2).transform.position - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val2;
					}
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				((EnemyAI)masked).SetMovingTowardsTargetPlayer(val);
				if (((EnemyAI)masked).currentBehaviourStateIndex != 1)
				{
					((EnemyAI)masked).SwitchToBehaviourState(1);
				}
			}
		}
	}
	internal sealed class BulbDeathScreen : MonoBehaviour
	{
		internal static BulbDeathScreen Current;

		private PlayerControllerB player;

		private float started;

		private float length;

		private Image black;

		private Image icon;

		private RawImage view;

		private RectTransform iconRect;

		private RectTransform viewRect;

		private Camera cam;

		private RenderTexture rt;

		private GameObject camGo;

		private GameObject lightGo;

		private Transform head;

		private readonly List<(Renderer r, ShadowCastingMode mode)> restore = new List<(Renderer, ShadowCastingMode)>();

		internal RawImage View => view;

		internal Camera Cam => cam;

		internal static void Show(PlayerControllerB p, float seconds)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)p == (Object)null))
			{
				if ((Object)(object)Current != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)Current).gameObject);
				}
				Current = new GameObject("BulbDeathScreen").AddComponent<BulbDeathScreen>();
				Current.Build(p, seconds);
			}
		}

		private void Build(PlayerControllerB p, float seconds)
		{
			//IL_0052: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0174: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_035f: Expected O, but got Unknown
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Expected O, but got Unknown
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			player = p;
			length = seconds;
			started = Time.realtimeSinceStartup;
			Canvas obj = ((Component)this).gameObject.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 900;
			CanvasScaler obj2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1280f, 720f);
			obj2.matchWidthOrHeight = 1f;
			black = NewImage("Dark", out var rect);
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			RectTransform obj3 = rect;
			Vector2 offsetMin = (rect.offsetMax = Vector2.zero);
			obj3.offsetMin = offsetMin;
			((Graphic)black).color = new Color(0f, 0f, 0f, 0f);
			rt = new RenderTexture(640, 640, 24, (RenderTextureFormat)0)
			{
				name = "BulbDeathView"
			};
			GameObject val = new GameObject("Character", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			viewRect = (RectTransform)val.transform;
			RectTransform obj4 = viewRect;
			RectTransform obj5 = viewRect;
			RectTransform obj6 = viewRect;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			obj6.pivot = val2;
			offsetMin = (obj5.anchorMax = val2);
			obj4.anchorMin = offsetMin;
			viewRect.sizeDelta = new Vector2(560f, 560f);
			viewRect.anchoredPosition = new Vector2(0f, -40f);
			view = val.AddComponent<RawImage>();
			view.texture = (Texture)(object)rt;
			((Graphic)view).raycastTarget = false;
			((Graphic)view).color = new Color(1f, 1f, 1f, 0f);
			icon = NewImage("OriginalBulbFailure", out iconRect);
			RectTransform obj7 = iconRect;
			RectTransform obj8 = iconRect;
			RectTransform obj9 = iconRect;
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			obj9.pivot = val2;
			offsetMin = (obj8.anchorMax = val2);
			obj7.anchorMin = offsetMin;
			iconRect.sizeDelta = new Vector2(84f, 98f);
			iconRect.anchoredPosition = new Vector2(0f, 270f);
			icon.sprite = BulbHealth.OriginalBulbGlyph;
			icon.preserveAspect = true;
			Transform[] array = (Transform[])(((Object)(object)p.thisPlayerModel != (Object)null) ? ((Array)p.thisPlayerModel.bones) : ((Array)new Transform[0]));
			foreach (Transform val5 in array)
			{
				if ((Object)(object)val5 != (Object)null && ((Object)val5).name == "spine.004")
				{
					head = val5;
				}
			}
			Renderer[] array2 = (Renderer[])(object)new Renderer[3]
			{
				(Renderer)p.thisPlayerModel,
				(Renderer)p.thisPlayerModelLOD1,
				(Renderer)p.thisPlayerModelLOD2
			};
			foreach (Renderer val6 in array2)
			{
				if ((Object)(object)val6 != (Object)null)
				{
					restore.Add((val6, val6.shadowCastingMode));
					val6.shadowCastingMode = (ShadowCastingMode)1;
				}
			}
			camGo = new GameObject("BulbDeathCam");
			cam = camGo.AddComponent<Camera>();
			cam.targetTexture = rt;
			cam.fieldOfView = 40f;
			cam.nearClipPlane = 0.05f;
			cam.farClipPlane = 12f;
			cam.clearFlags = (CameraClearFlags)2;
			cam.backgroundColor = Color.black;
			cam.cullingMask = (((Object)(object)p.thisPlayerModel != (Object)null) ? (1 << ((Component)p.thisPlayerModel).gameObject.layer) : (-1));
			HDAdditionalCameraData obj10 = camGo.AddComponent<HDAdditionalCameraData>();
			obj10.clearColorMode = (ClearColorMode)1;
			obj10.backgroundColorHDR = Color.black;
			obj10.customRenderingSettings = true;
			FrameSettingsOverrideMask renderingPathCustomFrameSettingsOverrideMask = obj10.renderingPathCustomFrameSettingsOverrideMask;
			((BitArray128)(ref renderingPathCustomFrameSettingsOverrideMask.mask))[27u] = true;
			((BitArray128)(ref renderingPathCustomFrameSettingsOverrideMask.mask))[28u] = true;
			obj10.renderingPathCustomFrameSettingsOverrideMask = renderingPathCustomFrameSettingsOverrideMask;
			((FrameSettings)(ref obj10.renderingPathCustomFrameSettings)).SetEnabled((FrameSettingsField)27, false);
			((FrameSettings)(ref obj10.renderingPathCustomFrameSettings)).SetEnabled((FrameSettingsField)28, false);
			lightGo = new GameObject("BulbDeathLight");
			HDAdditionalLightData obj11 = GameObjectExtension.AddHDLight(lightGo, (HDLightTypeAndShape)0);
			obj11.SetIntensity(900f, (LightUnit)0);
			obj11.SetRange(5f);
			obj11.SetColor(new Color(1f, 0.72f, 0.42f), -1f);
			PlaceCamera(0f);
		}

		private Image NewImage(string name, out RectTransform rect)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			rect = (RectTransform)val.transform;
			Image obj = val.AddComponent<Image>();
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private void PlaceCamera(float t)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0151: 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)
			if (!((Object)(object)player == (Object)null) && !((Object)(object)camGo == (Object)null))
			{
				Transform obj = (((Object)(object)player.thisPlayerBody != (Object)null) ? player.thisPlayerBody : ((Component)player).transform);
				Vector3 val = (((Object)(object)head != (Object)null) ? head.position : ((Component)player.gameplayCamera).transform.position);
				Vector3 val2 = Vector3.ProjectOnPlane(obj.forward, Vector3.up);
				Vector3 val3 = ((Vector3)(ref val2)).normalized;
				if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
				{
					val3 = Vector3.forward;
				}
				Vector3 val4 = Random.insideUnitSphere * 0.012f * Mathf.Clamp01(t / 0.6f);
				camGo.transform.position = val + val3 * 1.45f + Vector3.up * 0.05f + val4;
				camGo.transform.LookAt(val - Vector3.up * 0.2f);
				lightGo.transform.position = val + val3 * 1.1f + Vector3.up * 0.6f;
			}
		}

		private void LateUpdate()
		{
			//IL_0084: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_0152: 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)
			float num = Time.realtimeSinceStartup - started;
			if (num >= length || (Object)(object)player == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			PlaceCamera(num);
			float num2 = Mathf.Clamp01(num / 0.3f);
			float num3 = ((num > length - 0.4f) ? Mathf.Clamp01((length - num) / 0.4f) : 1f);
			((Graphic)black).color = new Color(0f, 0f, 0f, num2);
			((Graphic)view).color = new Color(1f, 1f, 1f, Mathf.Clamp01((num - 0.15f) / 0.3f) * num3);
			float num4 = 1f + 0.08f * Mathf.Sin(Mathf.Clamp01(num / 0.35f) * MathF.PI);
			((Transform)viewRect).localScale = Vector3.one * num4;
			iconRect.anchoredPosition = new Vector2(Mathf.Sin(num * 27f) * Mathf.Clamp01(num / 0.7f) * 3f, 270f);
			((Transform)iconRect).localScale = Vector3.one * (1f + 0.13f * Mathf.Sin(num * 13f));
			float num5 = num3 * num2;
			if (num > 2.4f && Mathf.Sin(num * 31f) < 0f)
			{
				num5 *= 0.28f;
			}
			((Graphic)icon).color = new Color(1f, 0.48f, 0.1f, num5);
		}

		private void OnDestroy()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			foreach (var (val, shadowCastingMode) in restore)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.shadowCastingMode = shadowCastingMode;
				}
			}
			if ((Object)(object)cam != (Object)null)
			{
				cam.targetTexture = null;
			}
			if ((Object)(object)camGo != (Object)null)
			{
				Object.Destroy((Object)(object)camGo);
			}
			if ((Object)(object)lightGo != (Object)null)
			{
				Object.Destroy((Object)(object)lightGo);
			}
			if ((Object)(object)rt != (Object)null)
			{
				rt.Release();
				Object.Destroy((Object)(object)rt);
			}
			if ((Object)(object)Current == (Object)(object)this)
			{
				Current = null;
			}
		}
	}
	[HarmonyPatch]
	internal sealed class BulbHealth : MonoBehaviour
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnRequest;

			public static HandleNamedMessageDelegate <1>__OnState;
		}

		private const string Request = "LethalGoHome_BulbRequest_v1";

		private const string State = "LethalGoHome_BulbState_v1";

		private const int WaitDays = 5;

		private const int HitPointsPerBulb = 34;

		private const int MaxExtra = 6;

		private const byte Sync = 0;

		private const byte Found = 1;

		private const byte Buy = 2;

		private const byte Use = 3;

		private const byte UseUpgrade = 4;

		private const byte ResultNone = 0;

		private const byte ResultInstalled = 1;

		private const byte ResultLocked = 2;

		private const byte ResultAlreadyInstalled = 3;

		private const byte ResultNoCredits = 4;

		private const byte ResultUnavailable = 5;

		private static BulbHealth instance;

		private static bool serverFound;

		private static int serverDays;

		private static string saveFile;

		private static bool registered;

		private static bool haveState;

		private static bool available;

		private static bool installed;

		private static int extra;

		private static int reserve;

		private static int shopPrice;

		private static float nextSync;

		private GameObject hud;

		private Image[] icons;

		private TextMeshProUGUI counter;

		private Sprite glyph;

		private Color hudColor;

		private int previousLit = -1;

		private AudioClip lifeChangeSound;

		private AudioSource hudAudio;

		private static float graceUntil;

		internal static int BulbsLost;

		internal static int FallsIgnored;

		private const float HudMarginX = 44f;

		private const float HudBottomY = 34f;

		private const float IconStep = 20f;

		private const float ZigZag = 13f;

		internal static bool IsAvailable
		{
			get
			{
				if (haveState)
				{
					return available;
				}
				return false;
			}
		}

		internal static bool IsInstalled
		{
			get
			{
				if (haveState)
				{
					return installed;
				}
				return false;
			}
		}

		internal static bool IsServerAvailable => BulbRules.Unlocked(serverFound, serverDays);

		internal static int Price => shopPrice;

		internal static int Reserve => reserve;

		internal static float IconSpacing => 20f;

		internal static RectTransform HudRect
		{
			get
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				if (!((Object)(object)instance != (Object)null) || !((Object)(object)instance.hud != (Object)null))
				{
					return null;
				}
				return (RectTransform)instance.hud.transform;
			}
		}

		internal static Sprite OriginalBulbGlyph
		{
			get
			{
				if (!((Object)(object)instance != (Object)null))
				{
					return null;
				}
				return instance.Glyph();
			}
		}

		internal static void Create(Plugin plugin)
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = ((Component)plugin).gameObject.AddComponent<BulbHealth>();
			}
		}

		internal static void Register()
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			registered = true;
			haveState = (available = (installed = false));
			extra = (reserve = 0);
			nextSync = 0f;
			if ((Object)(object)instance != (Object)null)
			{
				instance.ResetVisuals();
			}
			saveFile = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.currentSaveFileName : null);
			serverFound = false;
			serverDays = 0;
			if (singleton.IsServer && !string.IsNullOrEmpty(saveFile))
			{
				try
				{
					serverFound = ES3.Load<bool>("LGH_BulbFound", saveFile, false);
					serverDays = ES3.Load<int>("LGH_BulbDays", saveFile, 0);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not load bulb progression: " + ex.Message));
				}
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			object obj = <>O.<0>__OnRequest;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = OnRequest;
				<>O.<0>__OnRequest = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("LethalGoHome_BulbRequest_v1", (HandleNamedMessageDelegate)obj);
			CustomMessagingManager customMessagingManager2 = singleton.CustomMessagingManager;
			object obj2 = <>O.<1>__OnState;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = OnState;
				<>O.<1>__OnState = val2;
				obj2 = (object)val2;
			}
			customMessagingManager2.RegisterNamedMessageHandler("LethalGoHome_BulbState_v1", (HandleNamedMessageDelegate)obj2);
		}

		private static string PlayerKey(PlayerControllerB p)
		{
			if (p.playerSteamId == 0L)
			{
				return "name_" + p.playerUsername;
			}
			return p.playerSteamId.ToString();
		}

		private static PlayerControllerB Player(ulong client)
		{
			StartOfRound val = StartOfRound.Instance;
			if ((Object)(object)val == (Object)null || val.allPlayerScripts == null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = val.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if ((Object)(object)val2 != (Object)null && val2.isPlayerControlled && val2.actualClientId == client)
				{
					return val2;
				}
			}
			return null;
		}

		private static bool ReadInstalled(PlayerControllerB p)
		{
			if (string.IsNullOrEmpty(saveFile))
			{
				return false;
			}
			try
			{
				return ES3.Load<bool>("LGH_BulbInstalled_" + PlayerKey(p), saveFile, false);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read bulb upgrade: " + ex.Message));
				return false;
			}
		}

		private static int ReadExtra(PlayerControllerB p)
		{
			if (string.IsNullOrEmpty(saveFile))
			{
				return 0;
			}
			try
			{
				return Mathf.Clamp(ES3.Load<int>("LGH_BulbExtra_" + PlayerKey(p), saveFile, 0), 0, 6);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read bulb capacity: " + ex.Message));
				return 0;
			}
		}

		private static bool Save<T>(string key, T value)
		{
			if (string.IsNullOrEmpty(saveFile))
			{
				return false;
			}
			try
			{
				ES3.Save<T>(key, value, saveFile);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not save bulb progression: " + ex.Message));
				return false;
			}
		}

		private static FastBufferWriter Writer()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return new FastBufferWriter(64, (Allocator)2, -1);
		}

		private unsafe static void Send(byte operation, ulong id = 0uL)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!registered || (Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = Writer();
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref operation, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				if (singleton.IsServer)
				{
					FastBufferReader r = default(FastBufferReader);
					((FastBufferReader)(ref r))..ctor(val, (Allocator)2, -1, 0, (Allocator)2);
					try
					{
						OnRequest(singleton.LocalClientId, r);
						return;
					}
					finally
					{
						((IDisposable)(*(FastBufferReader*)(&r))/*cast due to .constrained prefix*/).Dispose();
					}
				}
				singleton.CustomMessagingManager.SendNamedMessage("LethalGoHome_BulbRequest_v1", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal static void SendFound()
		{
			Send(1, 0uL);
		}

		internal static void SendFoundUpgrade(HealthUpgradeItem item)
		{
			if ((Object)(object)item != (Object)null && (Object)(object)((NetworkBehaviour)item).NetworkObject != (Object)null)
			{
				Send(4, ((NetworkBehaviour)item).NetworkObjectId);
			}
		}

		internal static bool HealthIsExhausted(PlayerControllerB p)
		{
			if (haveState && installed && reserve <= 0 && (Object)(object)p != (Object)null)
			{
				return p.health <= 0;
			}
			return false;
		}

		internal static bool ServerHasUpgrade(PlayerControllerB player)
		{
			if ((Object)(object)player != (Object)null)
			{
				return ReadInstalled(player);
			}
			return false;
		}

		internal static void BuyUpgrade()
		{
			Send(2, 0uL);
		}

		internal static void SendUse(LightbulbItem item)
		{
			if (!installed)
			{
				HUDManager obj = HUDManager.Instance;
				if (obj != null)
				{
					obj.DisplayTip("Lightbulb", "The bulb can be sold as scrap.", false, false, "LC_Tip1");
				}
			}
			else if ((Object)(object)item != (Object)null && (Object)(object)((NetworkBehaviour)item).NetworkObject != (Object)null)
			{
				Send(3, ((NetworkBehaviour)item).NetworkObjectId);
			}
		}

		private static void OnRequest(ulong sender, FastBufferReader r)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				return;
			}
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			ulong num = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref num, default(ForPrimitives));
			PlayerControllerB val = Player(sender);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (b == 1 && !serverFound)
			{
				serverFound = true;
				serverDays = 0;
				Save("LGH_BulbFound", value: true);
				Save("LGH_BulbDays", 0);
			}
			byte b2 = 0;
			if (b == 2 || b == 4)
			{
				bool unlocked = BulbRules.Unlocked(serverFound, serverDays);
				bool flag = ReadInstalled(val);
				if (b == 2)
				{
					Terminal val2 = Object.FindObjectOfType<Terminal>();
					int num2 = Mathf.Max(0, CartConfig.LightbulbUpgradePrice.Value);
					b2 = BulbRules.PurchaseCheck(unlocked, flag, ((Object)(object)val2 != (Object)null) ? val2.groupCredits : (-1), num2);
					if ((Object)(object)val2 == (Object)null && (b2 == 0 || b2 == 4))
					{
						b2 = 5;
					}
					if (b2 == 0 && !Save("LGH_BulbInstalled_" + PlayerKey(val), value: true))
					{
						b2 = 5;
					}
					if (b2 == 0)
					{
						val2.groupCredits -= num2;
						val2.SyncGroupCreditsClientRpc(val2.groupCredits, -1);
						b2 = 1;
					}
				}
				else
				{
					singleton.SpawnManager.SpawnedObjects.TryGetValue(num, out var value);
					HealthUpgradeItem healthUpgradeItem = (((Object)(object)value != (Object)null) ? ((Component)value).GetComponent<HealthUpgradeItem>() : null);
					bool validUnusedItem = (Object)(object)healthUpgradeItem != (Object)null && !healthUpgradeItem.healthUsed && value.OwnerClientId == sender && ((GrabbableObject)healthUpgradeItem).heldByPlayerOnServer;
					b2 = BulbRules.FoundItemCheck(unlocked, flag, validUnusedItem);
					if (b2 == 0 && !Save("LGH_BulbInstalled_" + PlayerKey(val), value: true))
					{
						b2 = 5;
					}
					if (b2 == 0)
					{
						healthUpgradeItem.healthUsed = true;
						b2 = 1;
					}
				}
			}
			if (b == 3 && ReadInstalled(val) && ReadExtra(val) < 6 && singleton.SpawnManager.SpawnedObjects.TryGetValue(num, out var value2))
			{
				LightbulbItem lightbulbItem = (((Object)(object)value2 != (Object)null) ? ((Component)value2).GetComponent<LightbulbItem>() : null);
				if ((Object)(object)lightbulbItem != (Object)null && !lightbulbItem.healthUsed && value2.OwnerClientId == sender && ((GrabbableObject)lightbulbItem).heldByPlayerOnServer && Save("LGH_BulbExtra_" + PlayerKey(val), ReadExtra(val) + 1))
				{
					lightbulbItem.healthUsed = true;
				}
			}
			Reply(sender, val, (b == 3 || b == 4) ? num : 0, b2);
		}

		private unsafe static void Reply(ulong client, PlayerControllerB p, ulong id, byte result = 0)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			FastBufferWriter val = Writer();
			try
			{
				bool flag = BulbRules.Unlocked(serverFound, serverDays);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				flag = ReadInstalled(p);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				int num = ReadExtra(p);
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref result, default(ForPrimitives));
				num = Mathf.Max(0, CartConfig.LightbulbUpgradePrice.Value);
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				if (client == singleton.LocalClientId)
				{
					FastBufferReader r = default(FastBufferReader);
					((FastBufferReader)(ref r))..ctor(val, (Allocator)2, -1, 0, (Allocator)2);
					try
					{
						OnState(0uL, r);
						return;
					}
					finally
					{
						((IDisposable)(*(FastBufferReader*)(&r))/*cast due to .constrained prefix*/).Dispose();
					}
				}
				singleton.CustomMessagingManager.SendNamedMessage("LethalGoHome_BulbState_v1", client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal static void DebugUnlock()
		{
			serverFound = true;
			serverDays = 5;
			Broadcast();
		}

		private static void Broadcast()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			StartOfRound val = StartOfRound.Instance;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || (Object)(object)val == (Object)null || val.allPlayerScripts == null)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = val.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if ((Object)(object)val2 != (Object)null && val2.isPlayerControlled)
				{
					Reply(val2.actualClientId, val2, 0uL, 0);
				}
			}
		}

		private static void OnState(ulong sender, FastBufferReader r)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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)
			if (sender != 0L)
			{
				return;
			}
			bool flag = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			bool flag2 = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong num2 = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref num2, default(ForPrimitives));
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			int num3 = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num3, default(ForPrimitives));
			shopPrice = Mathf.Max(0, num3);
			bool num4 = !haveState;
			int num5 = extra;
			bool flag3 = installed;
			available = flag;
			installed = flag2;
			extra = Mathf.Clamp(num, 0, 6);
			haveState = true;
			if (num4 || (!flag3 && flag2))
			{
				reserve = extra * 34;
			}
			else if (extra > num5)
			{
				reserve += (extra - num5) * 34;
			}
			reserve = Mathf.Clamp(reserve, 0, extra * 34);
			if (num2 != 0L && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(num2, out var value))
			{
				LightbulbItem component = ((Component)value).GetComponent<LightbulbItem>();
				if ((Object)(object)component != (Object)null && extra > num5)
				{
					component.healthUsed = true;
				}
				HealthUpgradeItem component2 = ((Component)value).GetComponent<HealthUpgradeItem>();
				if ((Object)(object)component2 != (Object)null && b == 1)
				{
					component2.healthUsed = true;
				}
			}
			if ((Object)(object)instance != (Object)null)
			{
				instance.ResetVisuals();
			}
			if (num2 != 0L && b == 0 && extra == num5)
			{
				HUDManager obj = HUDManager.Instance;
				if (obj != null)
				{
					obj.DisplayTip("Lightbulb", "This bulb could not add capacity; it may already have been used or you may be at the limit.", false, false, "LC_Tip1");
				}
			}
			switch (b)
			{
			case 1:
			{
				HUDManager obj3 = HUDManager.Instance;
				if (obj3 != null)
				{
					obj3.DisplayTip("Lightbulb health", "Installed! Use a lightbulb to increase your capacity.", false, false, "LC_Tip1");
				}
				break;
			}
			case 2:
			{
				HUDManager obj5 = HUDManager.Instance;
				if (obj5 != null)
				{
					obj5.DisplayTip("Lightbulb health", "The upgrade is not available yet.", false, false, "LC_Tip1");
				}
				break;
			}
			case 3:
			{
				HUDManager obj6 = HUDManager.Instance;
				if (obj6 != null)
				{
					obj6.DisplayTip("Lightbulb health", "You already have this upgrade.", false, false, "LC_Tip1");
				}
				break;
			}
			case 4:
			{
				HUDManager obj4 = HUDManager.Instance;
				if (obj4 != null)
				{
					obj4.DisplayTip("Lightbulb health", "The crew does not have enough credits.", false, false, "LC_Tip1");
				}
				break;
			}
			case 5:
			{
				HUDManager obj2 = HUDManager.Instance;
				if (obj2 != null)
				{
					obj2.DisplayTip("Lightbulb health", "Could not install the upgrade. Check the item or host save.", false, false, "LC_Tip1");
				}
				break;
			}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void StartRound()
		{
			Register();
		}

		[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
		[HarmonyPostfix]
		private static void DayPassed()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.IsServer && serverFound && serverDays < 5)
			{
				serverDays = BulbRules.Advance(serverFound, serverDays);
				Save("LGH_BulbDays", serverDays);
				Broadcast();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
		[HarmonyPostfix]
		private static void Revived()
		{
			if (installed)
			{
				reserve = extra * 34;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		[HarmonyPrefix]
		private static bool Damage(PlayerControllerB __instance, ref int damageNumber, bool fallDamage, CauseOfDeath causeOfDeath)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if (!installed || !((NetworkBehaviour)__instance).IsOwner || __instance.isPlayerDead || !__instance.AllowPlayerDeath() || damageNumber <= 0)
			{
				return true;
			}
			if ((fallDamage || ((int)causeOfDeath == 2 && __instance.takingFallDamage)) && CartConfig.BulbNoFallDamage.Value)
			{
				__instance.takingFallDamage = false;
				FallsIgnored++;
				return false;
			}
			if (Time.time < graceUntil)
			{
				return false;
			}
			damageNumber = BulbRules.Hit(ref reserve, __instance.health, damageNumber);
			graceUntil = Time.time + CartConfig.BulbHitGrace.Value;
			BulbsLost++;
			return true;
		}

		private void Update()
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!registered || (Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				if ((Object)(object)hud != (Object)null)
				{
					hud.SetActive(false);
				}
				return;
			}
			if (!haveState && Time.unscaledTime >= nextSync)
			{
				nextSync = Time.unscaledTime + 3f;
				Send(0, 0uL);
			}
			if (installed && (Object)(object)hud == (Object)null)
			{
				BuildHud();
			}
			if (!((Object)(object)hud != (Object)null))
			{
				return;
			}
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			bool flag = installed && (Object)(object)val != (Object)null && !val.isPlayerDead && (Object)(object)HUDManager.Instance != (Object)null;
			if (hud.activeSelf != flag)
			{
				hud.SetActive(flag);
			}
			if (flag && icons != null)
			{
				int num = Mathf.Clamp(BulbRules.Lit(val.health, reserve), 0, 3 + extra);
				if (previousLit >= 0 && num != previousLit && (Object)(object)hudAudio != (Object)null && (Object)(object)lifeChangeSound != (Object)null)
				{
					hudAudio.PlayOneShot(lifeChangeSound, 0.7f);
				}
				previousLit = num;
				for (int i = 0; i < icons.Length; i++)
				{
					((Graphic)icons[i]).color = new Color(hudColor.r, hudColor.g, hudColor.b, (i < num) ? 1f : 0.16f);
				}
				((TMP_Text)counter).text = "BULBS  " + num + " / " + (3 + extra);
			}
			else
			{
				previousLit = -1;
			}
		}

		private void ResetVisuals()
		{
			if ((Object)(object)hud != (Object)null)
			{
				Object.Destroy((Object)(object)hud);
			}
			hud = null;
			icons = null;
			hudAudio = null;
			previousLit = -1;
		}

		private Sprite Glyph()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)glyph != (Object)null)
			{
				return glyph;
			}
			try
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "RGHHealthBulb",
					filterMode = (FilterMode)1
				};
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(Plugin.PluginDir, "GameAssets", "health_bulb_glyph.png"))))
				{
					Color32[] pixels = val.GetPixels32();
					int width = ((Texture)val).width;
					int height = ((Texture)val).height;
					Color32[] array = (Color32[])(object)new Color32[pixels.Length];
					for (int i = 0; i < height; i++)
					{
						Array.Copy(pixels, i * width, array, (height - 1 - i) * width, width);
					}
					val.SetPixels32(array);
					val.Apply();
					return glyph = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not load original bulb HUD icon: " + ex.Message));
			}
			return glyph = CartIcon.CreateLightbulb();
		}

		private void BuildHud()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_017c: 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_01a0: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: 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_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			HUDManager val = HUDManager.Instance;
			if ((Object)(object)val == (Object)null || (Object)(object)val.HUDContainer == (Object)null)
			{
				return;
			}
			Sprite val2 = Glyph();
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			int num = 3 + extra;
			float num2 = Mathf.Max(188f, 120f);
			hud = new GameObject("BulbHealthHud", new Type[1] { typeof(RectTransform) });
			hud.transform.SetParent(val.HUDContainer.transform, false);
			hudAudio = hud.AddComponent<AudioSource>();
			hudAudio.playOnAwake = false;
			hudAudio.spatialBlend = 0f;
			if ((Object)(object)lifeChangeSound == (Object)null)
			{
				lifeChangeSound = CartAudio.TryLoadWav("bulb_life_change");
			}
			RectTransform val3 = (RectTransform)hud.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(1f, 0f);
			val3.anchorMax = val4;
			val3.anchorMin = val4;
			val3.pivot = new Vector2(1f, 0f);
			val3.anchoredPosition = new Vector2(-44f, 34f);
			val3.sizeDelta = new Vector2(num2, 64f);
			hud.AddComponent<AdaptiveBulbHud>().Initialize();
			hudColor = (Color)(((Object)(object)val.weightCounter != (Object)null) ? ((Graphic)val.weightCounter).color : new Color(1f, 0.43f, 0f));
			GameObject val5 = new GameObject("HealthLabel", new Type[1] { typeof(RectTransform) });
			val5.transform.SetParent(hud.transform, false);
			RectTransform val6 = (RectTransform)val5.transform;
			Vector2 val7 = default(Vector2);
			((Vector2)(ref val7))..ctor(1f, 1f);
			val6.pivot = val7;
			val4 = (val6.anchorMin = (val6.anchorMax = val7));
			val6.anchoredPosition = Vector2.zero;
			val6.sizeDelta = new Vector2(num2, 20f);
			counter = val5.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)val.weightCounter != (Object)null)
			{
				((TMP_Text)counter).font = ((TMP_Text)val.weightCounter).font;
			}
			((TMP_Text)counter).fontSize = 14f;
			((Graphic)counter).color = hudColor;
			((Graphic)counter).raycastTarget = false;
			((TMP_Text)counter).alignment = (TextAlignmentOptions)516;
			icons = (Image[])(object)new Image[num];
			for (int i = 0; i < icons.Length; i++)
			{
				GameObject val10 = new GameObject("Bulb" + i, new Type[1] { typeof(RectTransform) });
				val10.transform.SetParent(hud.transform, false);
				RectTransform val11 = (RectTransform)val10.transform;
				((Vector2)(ref val7))..ctor(1f, 0f);
				val11.pivot = val7;
				val4 = (val11.anchorMin = (val11.anchorMax = val7));
				val11.anchoredPosition = new Vector2((float)(-(num - 1 - i)) * 20f, (i % 2 == 0) ? 13f : 0f);
				val11.sizeDelta = new Vector2(26f, 29f);
				if (i % 2 == 1)
				{
					val10.transform.SetAsLastSibling();
				}
				icons[i] = val10.AddComponent<Image>();
				icons[i].sprite = val2;
				icons[i].preserveAspect = true;
				((Graphic)icons[i]).raycastTarget = false;
			}
		}
	}
	internal static class BulbRules
	{
		internal const int WaitDays = 5;

		internal const int HitPointsPerBulb = 34;

		internal const int BaseBulbs = 3;

		internal const int MaxBulbs = 9;

		internal const int MaxExtra = 6;

		internal static bool Unlocked(bool found, int days)
		{
			if (found)
			{
				return days >= 5;
			}
			return false;
		}

		internal static byte PurchaseCheck(bool unlocked, bool installed, int credits, int price)
		{
			if (!unlocked)
			{
				return 2;
			}
			if (installed)
			{
				return 3;
			}
			if (credits < price)
			{
				return 4;
			}
			return 0;
		}

		internal static byte FoundItemCheck(bool unlocked, bool installed, bool validUnusedItem)
		{
			if (!unlocked)
			{
				return 2;
			}
			if (installed)
			{
				return 3;
			}
			if (!validUnusedItem)
			{
				return 5;
			}
			return 0;
		}

		internal static int Advance(bool found, int days)
		{
			if (!found || days >= 5)
			{
				return days;
			}
			return days + 1;
		}

		internal static int Absorb(ref int reserve, int damage)
		{
			if (damage <= 0 || reserve <= 0)
			{
				return damage;
			}
			int num = ((damage < reserve) ? damage : reserve);
			reserve -= num;
			return damage - num;
		}

		internal static int Hit(ref int reserve, int hp, int damage)
		{
			if (damage <= 0)
			{
				return damage;
			}
			if (reserve > 0)
			{
				reserve = ((reserve > 34) ? (reserve - 34) : 0);
				return 0;
			}
			int num = Lit(hp, 0);
			if (num <= 1)
			{
				if (hp <= 50)
				{
					return 50;
				}
				return hp;
			}
			return hp - (num - 1) * 100 / 3;
		}

		internal static int Lit(int hp, int shield)
		{
			int num = ((hp > 0) ? ((hp * 3 + 99) / 100) : 0);
			int num2 = ((shield > 0) ? ((shield + 34 - 1) / 34) : 0);
			return num + num2;
		}
	}
	internal static class CameraFacing
	{
		private static bool hooked;

		private static bool warned;

		internal static event Action<Camera> BeforeRender;

		internal static void Hook()
		{
			if (hooked)
			{
				return;
			}
			hooked = true;
			RenderPipelineManager.beginCameraRendering += delegate(ScriptableRenderContext _, Camera cam)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Invalid comparison between Unknown and I4
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Invalid comparison between Unknown and I4
				if ((Object)(object)cam == (Object)null || (int)cam.cameraType == 16 || (int)cam.cameraType == 4)
				{
					return;
				}
				try
				{
					CameraFacing.BeforeRender?.Invoke(cam);
				}
				catch (Exception ex)
				{
					if (!warned)
					{
						Plugin.Log.LogWarning((object)("Camera-facing effect failed: " + ex));
					}
					warned = true;
				}
			};
		}
	}
	internal sealed class FacingCard : MonoBehaviour
	{
		internal enum Mode
		{
			Full,
			Axial,
			Cap
		}

		internal Transform follow;

		internal Vector3 offset;

		internal Vector3 axis = Vector3.forward;

		internal Vector2 size = Vector2.one;

		internal Mode mode;

		internal float roll;

		internal bool visible = true;

		internal MeshRenderer card;

		internal Vector3 LastForward { get; private set; }

		internal static FacingCard Create(Transform follow, string name, Material material, Mode mode, Vector3 offset, Vector2 size)
		{
			//IL_0028: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			CameraFacing.Hook();
			MeshRenderer val = GameEffectAssets.Card(null, name, material);
			FacingCard facingCard = ((Component)val).gameObject.AddComponent<FacingCard>();
			facingCard.follow = follow;
			facingCard.mode = mode;
			facingCard.offset = offset;
			facingCard.size = size;
			facingCard.card = val;
			((Renderer)val).enabled = false;
			return facingCard;
		}

		private void OnEnable()
		{
			CameraFacing.BeforeRender += Face;
		}

		private void OnDisable()
		{
			CameraFacing.BeforeRender -= Face;
		}

		private void Face(Camera cam)
		{
			//IL_0075: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to inv

LethalGoHome.InputSupport.dll

Decompiled an hour ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using LethalCompanyInputUtils.Api;
using LethalGoHome;
using Microsoft.CodeAnalysis;
using UnityEngine.InputSystem;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalGoHomeInput
{
	public sealed class CartActions : LcInputActions
	{
		[InputAction("<Keyboard>/b", Name = "Cart boost / jet thrust")]
		public InputAction CartBoost { get; set; }

		[InputAction("<Keyboard>/leftBracket", Name = "Old radio previous track")]
		public InputAction RadioPrevious { get; set; }

		[InputAction("<Keyboard>/rightBracket", Name = "Old radio next track")]
		public InputAction RadioNext { get; set; }

		[InputAction("<Keyboard>/backslash", Name = "Old radio power")]
		public InputAction RadioPower { get; set; }
	}
	[BepInPlugin("lethalgohome.inputsupport", "Lethal Go Home Input Support", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class InputPlugin : BaseUnityPlugin
	{
		private CartActions actions;

		private void Awake()
		{
			actions = new CartActions();
			actions.CartBoost.performed += BoostDown;
			actions.CartBoost.canceled += BoostUp;
			actions.RadioPrevious.performed += Previous;
			actions.RadioNext.performed += Next;
			actions.RadioPower.performed += Power;
		}

		private void OnDestroy()
		{
			if (actions != null)
			{
				actions.CartBoost.performed -= BoostDown;
				actions.CartBoost.canceled -= BoostUp;
				actions.RadioPrevious.performed -= Previous;
				actions.RadioNext.performed -= Next;
				actions.RadioPower.performed -= Power;
			}
		}

		private static void BoostDown(CallbackContext c)
		{
			RebindableActions.CartBoost(true);
		}

		private static void BoostUp(CallbackContext c)
		{
			RebindableActions.CartBoost(false);
		}

		private static void Previous(CallbackContext c)
		{
			RebindableActions.RadioPrevious();
		}

		private static void Next(CallbackContext c)
		{
			RebindableActions.RadioNext();
		}

		private static void Power(CallbackContext c)
		{
			RebindableActions.RadioPower();
		}
	}
}

LethalGoHome.PlayerModel.dll

Decompiled an hour ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using LethalGoHome;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalGoHomePlayer
{
	[BepInPlugin("lethalgohome.rabbidplayer", "Lethal Go Home Rabbid Player", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class PlayerPlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			ModelReplacementAPI.RegisterSuitModelReplacement("Rabbid", typeof(RabbidReplacement));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered experimental Rabbid suit model replacement.");
		}
	}
	public sealed class RabbidReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			GameObject obj = RabbidPlayerModelFactory.Create();
			obj.AddComponent<OffsetBuilder>().GenerateViewModel = false;
			Object.Destroy((Object)(object)obj);
			return obj;
		}
	}
}