Decompiled source of RestoreMapper v1.5.0

RestoreMapper.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using RestoreMapper.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("RestoreMapper")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Restore the unused mapper item in the shop")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.5.0+873919297f67f38112ed3984b91fccbcb8108993")]
[assembly: AssemblyProduct("RestoreMapper")]
[assembly: AssemblyTitle("RestoreMapper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 RestoreMapper
{
	internal static class LobbyCompatibility
	{
		internal static void Init()
		{
			PluginHelper.RegisterPlugin("butterystancakes.lethalcompany.restoremapper", Version.Parse("1.5.0"), (CompatibilityLevel)2, (VersionStrictness)0);
		}
	}
	public class MapperScreen : MonoBehaviour
	{
		public Camera cam;

		public Light light;

		public Renderer transition;

		public PlayerControllerB target;

		public LineRenderer line;

		public bool drawPath;

		private NavMeshPath path;

		private Canvas mapperCanvas;

		private float ratio = 1f;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if ((Object)(object)cam == (Object)null)
			{
				cam = ((Component)this).GetComponent<Camera>();
			}
			path = new NavMeshPath();
			SetupCanvas();
			SetupLine();
		}

		private void LateUpdate()
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				Vector3 position = ((Component)target).transform.position;
				position.y += 3.636f;
				((Component)this).transform.position = position;
			}
		}

		private void OnDisable()
		{
			target = null;
			drawPath = false;
		}

		private void OnDestroy()
		{
			if ((Object)(object)mapperCanvas != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)mapperCanvas).gameObject);
			}
		}

		private void OnEnable()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_012c: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || ((Component)target).transform.position.y >= -80f || (Object)(object)RMNetworker.Instance == (Object)null || !RMNetworker.Instance.ShowPath.Value)
			{
				return;
			}
			bool flag = RoundManager.Instance.currentDungeonType == 4 && (Object)(object)RoundManager.Instance.currentMineshaftElevator != (Object)null;
			if ((!flag || !(Vector3.Distance(((Component)target).transform.position, RoundManager.Instance.currentMineshaftElevator.elevatorInsidePoint.position) <= 1f)) && NavMesh.CalculatePath(((Component)target).transform.position, (flag && !((Bounds)(ref RestoreMapperPatches.mineStartBounds)).Contains(((Component)target).transform.position)) ? RoundManager.Instance.currentMineshaftElevator.elevatorBottomPoint.position : RestoreMapperPatches.mainEntrancePos, -1, path) && path.corners.Length >= 2)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[path.corners.Length];
				for (int i = 0; i < path.corners.Length; i++)
				{
					array[i] = path.corners[i] + Vector3.up * 1.25f;
				}
				line.positionCount = Mathf.Min(array.Length, 50);
				line.SetPositions(array);
				drawPath = true;
			}
		}

		private void SetupCanvas()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			mapperCanvas = Object.Instantiate<GameObject>(((Component)StartOfRound.Instance.radarCanvas).gameObject, ((Component)StartOfRound.Instance.radarCanvas).transform.parent, true).GetComponent<Canvas>();
			foreach (Transform item in ((Component)mapperCanvas).transform)
			{
				Transform val = item;
				if (((Object)val).name == "MonitoringPlayerUIContainer")
				{
					foreach (Transform item2 in val)
					{
						Transform val2 = item2;
						if (((Object)val2).name == "CompassRose")
						{
							((Component)val2).gameObject.SetActive(true);
						}
						else
						{
							Object.Destroy((Object)(object)((Component)val2).gameObject);
						}
					}
					((Component)val).gameObject.SetActive(true);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			mapperCanvas.worldCamera = ((Component)this).GetComponent<Camera>();
			RenderTexture targetTexture = StartOfRound.Instance.mapScreen.cam.targetTexture;
			ratio = ((float)((Texture)cam.targetTexture).width / (float)((Texture)targetTexture).width + (float)((Texture)cam.targetTexture).height / (float)((Texture)targetTexture).height) / 2f;
			if (ratio != 1f)
			{
				Canvas obj = mapperCanvas;
				obj.scaleFactor *= ratio;
			}
		}

		private void SetupLine()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			line = Object.Instantiate<GameObject>(((Component)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit).gameObject, ((Component)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit).transform.parent, true).GetComponent<LineRenderer>();
			((Renderer)line).forceRenderingOff = true;
			((Renderer)line).material.SetTextureOffset("_MainTex", Vector2.zero);
			((Renderer)line).enabled = true;
		}
	}
	[BepInPlugin("butterystancakes.lethalcompany.restoremapper", "Restore Mapper", "1.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string PLUGIN_GUID = "butterystancakes.lethalcompany.restoremapper";

		internal const string PLUGIN_NAME = "Restore Mapper";

		internal const string PLUGIN_VERSION = "1.5.0";

		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> configLowQuality;

		internal static ConfigEntry<bool> configShowPath;

		internal static ConfigEntry<int> configPrice;

		internal static ConfigEntry<float> configBatteryUsage;

		private const string GUID_LOBBY_COMPATIBILITY = "BMX.LobbyCompatibility";

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			NetcodePatch();
			Logger = ((BaseUnityPlugin)this).Logger;
			if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
			{
				Logger.LogInfo((object)"CROSS-COMPATIBILITY - Lobby Compatibility detected");
				LobbyCompatibility.Init();
			}
			configPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Gameplay", "Price", 150, new ConfigDescription("How much should the mapper cost in the terminal store?", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 250000), Array.Empty<object>()));
			configBatteryUsage = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "Battery Usage", 5f, new ConfigDescription("How much battery does refreshing the view cost? Viewing the previous \"snapshot\" on the screen does not require battery.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			configShowPath = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "Show Path", false, "Should the mapper draw a line back to main entrance for its user?");
			configLowQuality = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "Low Quality", false, "Decreases the resolution of the mapper's image, to match the radar camera.\nThis will reduce memory usage and might also reduce lag spikes when activating the device.");
			new Harmony("butterystancakes.lethalcompany.restoremapper").PatchAll();
			RenderPipelineManager.beginCameraRendering += RenderingOverrides.OnBeginCameraRendering;
			RenderPipelineManager.endCameraRendering += RenderingOverrides.OnEndCameraRendering;
			Logger.LogInfo((object)"Restore Mapper v1.5.0 loaded");
		}

		private void NetcodePatch()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class RestoreMapperPatches
	{
		internal static Vector3 mainEntrancePos;

		internal static Bounds mineStartBounds;

		[HarmonyPatch(typeof(Terminal), "Awake")]
		[HarmonyPostfix]
		private static void Terminal_Post_Awake(Terminal __instance)
		{
			TerminalKeyword? obj = ((IEnumerable<TerminalKeyword>)__instance.terminalNodes?.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => ((Object)keyword).name == "Buy"));
			TerminalNode val = ((IEnumerable<CompatibleNoun>)obj?.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
			{
				TerminalKeyword noun = compatibleNoun.noun;
				return ((noun != null) ? ((Object)noun).name : null) == "Mapper";
			}).result;
			CompatibleNoun val2 = ((IEnumerable<CompatibleNoun>)val?.terminalOptions).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
			{
				TerminalKeyword noun = compatibleNoun.noun;
				return ((noun != null) ? ((Object)noun).name : null) == "Confirm";
			});
			List<Item> list = StartOfRound.Instance?.allItemsList?.itemsList;
			Item val3 = list?.FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "MapDevice"));
			if ((Object)(object)obj == (Object)null || (Object)(object)val == (Object)null || val2 == null || list == null || (Object)(object)val3 == (Object)null)
			{
				Plugin.Logger.LogError((object)"Encountered an error while caching essential references. Loading will be skipped.");
				return;
			}
			__instance.buyableItemsList = CollectionExtensions.AddItem<Item>((IEnumerable<Item>)__instance.buyableItemsList, val3).ToArray();
			val.buyItemIndex = __instance.buyableItemsList.Length - 1;
			val2.result.buyItemIndex = val.buyItemIndex;
			Plugin.Logger.LogDebug((object)"Assigned IDs");
			int num = (((Object)(object)RMNetworker.Instance != (Object)null && RMNetworker.Instance.Price.Value != 0) ? RMNetworker.Instance.Price.Value : 150);
			if (val3.creditsWorth != num)
			{
				val3.creditsWorth = num;
				Plugin.Logger.LogDebug((object)"Assigned price");
			}
			Item val4 = ((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "ProFlashlight"));
			if ((Object)(object)val4 != (Object)null)
			{
				val3.grabSFX = val4.grabSFX;
				val3.dropSFX = val4.dropSFX;
				val3.pocketSFX = val4.pocketSFX;
				Plugin.Logger.LogDebug((object)"Assigned SFX");
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Couldn't find pro-flashlight item. Sound effects will be missing.");
			}
			try
			{
				AssetBundle val5 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "restoremapper"));
				val3.itemIcon = val5.LoadAsset<Sprite>("MapperIcon");
				val5.Unload(false);
				Plugin.Logger.LogDebug((object)"Assigned special icon");
			}
			catch
			{
				Plugin.Logger.LogWarning((object)"Encountered some error loading asset bundle. Inventory icon will be incorrect.");
				Item val6 = list?.FirstOrDefault((Func<Item, bool>)delegate(Item item)
				{
					Sprite itemIcon = item.itemIcon;
					return ((itemIcon != null) ? ((Object)itemIcon).name : null) == "caticontest";
				});
				if ((Object)(object)val6 != (Object)null)
				{
					val3.itemIcon = val6.itemIcon;
				}
			}
		}

		[HarmonyPatch(typeof(MapDevice), "Start")]
		[HarmonyPrefix]
		private static bool MapDevice_Pre_Start(MapDevice __instance)
		{
			if ((Object)(object)__instance.mapCamera != (Object)null)
			{
				Plugin.Logger.LogWarning((object)$"Mapper #{((Object)__instance).GetInstanceID()} tried to call Start() more than once, this is dangerous and would've caused a memory leak");
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MapDevice), "Start")]
		[HarmonyPostfix]
		private static void MapDevice_Post_Start(MapDevice __instance)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			if (((Component)__instance.mapCamera).CompareTag("MapCamera"))
			{
				__instance.mapCamera = Object.Instantiate<GameObject>(((Component)__instance.mapCamera).gameObject, ((Component)__instance.mapCamera).transform.parent).GetComponent<Camera>();
				((Component)__instance.mapCamera).tag = "Untagged";
				RenderTexture targetTexture = __instance.mapCamera.targetTexture;
				int num = 655;
				int num2 = 455;
				if (Plugin.configLowQuality.Value)
				{
					num = ((Texture)targetTexture).width;
					num2 = ((Texture)targetTexture).height;
				}
				__instance.mapCamera.targetTexture = new RenderTexture(num, num2, targetTexture.depth, targetTexture.format);
				Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} camera and texture cloned");
				MapperScreen mapperScreen = ((Component)__instance.mapCamera).gameObject.AddComponent<MapperScreen>();
				mapperScreen.cam = __instance.mapCamera;
				__instance.mapLight = ((Component)__instance.mapCamera).GetComponentInChildren<Light>();
				mapperScreen.light = __instance.mapLight;
				__instance.mapAnimatorTransition = ((Component)__instance.mapCamera).GetComponentInChildren<Animator>();
				mapperScreen.transition = ((Component)__instance.mapAnimatorTransition).GetComponent<Renderer>();
				((Component)__instance.mapCamera).gameObject.SetActive(false);
				((Behaviour)__instance.mapCamera).enabled = true;
				((Behaviour)__instance.mapLight).enabled = false;
				mapperScreen.transition.forceRenderingOff = true;
				Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} light setup");
				MeshRenderer componentInChildren = ((Component)__instance).GetComponentInChildren<MeshRenderer>();
				Material[] materials = ((Renderer)componentInChildren).materials;
				((IEnumerable<Material>)materials).FirstOrDefault((Func<Material, bool>)((Material mat) => ((Object)mat).name.StartsWith("MapScreen"))).mainTexture = (Texture)(object)__instance.mapCamera.targetTexture;
				((Renderer)componentInChildren).materials = materials;
				Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} screen retextured");
				((Component)__instance.mapAnimatorTransition).transform.localPosition = new Vector3(0f, 0f, -0.95f);
			}
		}

		[HarmonyPatch(typeof(MapDevice), "ItemActivate")]
		[HarmonyPrefix]
		private static bool MapDevice_Pre_ItemActivate(MapDevice __instance)
		{
			if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null || (Object)(object)__instance.mapCamera == (Object)null || ((Component)__instance.mapCamera).CompareTag("MapCamera"))
			{
				return true;
			}
			if (__instance.pingMapCoroutine != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(__instance.pingMapCoroutine);
			}
			MapperScreen mapperScreen = default(MapperScreen);
			if (((Component)__instance.mapCamera).TryGetComponent<MapperScreen>(ref mapperScreen))
			{
				mapperScreen.target = ((GrabbableObject)__instance).playerHeldBy;
			}
			((MonoBehaviour)__instance).StartCoroutine(pingMapSystem(__instance));
			return false;
		}

		[HarmonyPatch(typeof(NetworkBehaviour), "OnDestroy")]
		[HarmonyPostfix]
		private static void NetworkBehaviour_Post_OnDestroy(NetworkBehaviour __instance)
		{
			MapDevice val = (MapDevice)(object)((__instance is MapDevice) ? __instance : null);
			if (val != null && (Object)(object)val.mapCamera != (Object)null && !((Component)val.mapCamera).CompareTag("MapCamera"))
			{
				if (val.mapCamera.targetTexture.IsCreated())
				{
					val.mapCamera.targetTexture.Release();
				}
				Object.Destroy((Object)(object)val.mapCamera.targetTexture);
				Object.Destroy((Object)(object)((Component)val.mapCamera).gameObject);
				Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} cleaned up");
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "UseItemBatteries")]
		[HarmonyPrefix]
		private static bool GrabbableObject_Pre_UseItemBatteries(GrabbableObject __instance)
		{
			if (!(__instance is MapDevice))
			{
				return true;
			}
			if (StartOfRound.Instance.inShipPhase || StartOfRound.Instance.mapScreen.overrideCameraForOtherUse)
			{
				return false;
			}
			if ((Object)(object)__instance.playerHeldBy == (Object)null || __instance.playerHeldBy.isInsideFactory)
			{
				return true;
			}
			if (!StartOfRound.Instance.mapScreen.checkedForContourMap)
			{
				StartOfRound.Instance.mapScreen.contourMap = GameObject.FindGameObjectWithTag("TerrainContourMap");
				StartOfRound.Instance.mapScreen.checkedForContourMap = true;
			}
			return true;
		}

		private static IEnumerator pingMapSystem(MapDevice mapDevice)
		{
			((Component)mapDevice.mapCamera).gameObject.SetActive(true);
			mapDevice.mapAnimatorTransition.SetTrigger("Transition");
			yield return (object)new WaitForSeconds(0.233f);
			((Component)mapDevice.mapCamera).gameObject.SetActive(false);
		}

		[HarmonyPatch(typeof(StartOfRound), "SwitchMapMonitorPurpose")]
		[HarmonyPostfix]
		private static void StartOfRound_Post_SwitchMapMonitorPurpose(bool displayInfo)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!displayInfo)
			{
				return;
			}
			RenderTexture active = RenderTexture.active;
			MapDevice[] array = Object.FindObjectsByType<MapDevice>((FindObjectsSortMode)0);
			foreach (MapDevice val in array)
			{
				if ((Object)(object)val.mapCamera != (Object)null && !((Component)val.mapCamera).CompareTag("MapCamera"))
				{
					((Component)val.mapCamera).gameObject.SetActive(false);
					RenderTexture.active = val.mapCamera.targetTexture;
					GL.Clear(true, true, Color.clear);
				}
			}
			RenderTexture.active = active;
		}

		[HarmonyPatch(typeof(MapDevice), "EquipItem")]
		[HarmonyPostfix]
		private static void MapDevice_Post_EquipItem(MapDevice __instance)
		{
			if ((Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null)
			{
				((GrabbableObject)__instance).playerHeldBy.equippedUsableItemQE = false;
				MapperScreen mapperScreen = default(MapperScreen);
				if ((Object)(object)__instance.mapCamera != (Object)null && ((Component)__instance.mapCamera).TryGetComponent<MapperScreen>(ref mapperScreen))
				{
					mapperScreen.target = ((GrabbableObject)__instance).playerHeldBy;
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void RoundManager_Post_FinishGeneratingNewLevelClientRpc(RoundManager __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsByType<EntranceTeleport>((FindObjectsSortMode)0)).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport teleport) => teleport.entranceId == 0 && !teleport.isEntranceToBuilding));
			mainEntrancePos = (((Object)(object)val != (Object)null) ? val.entrancePoint.position : Vector3.zero);
			if (__instance.currentDungeonType != 4)
			{
				return;
			}
			GameObject val2 = __instance.dungeonGenerator?.Root ?? GameObject.Find("/Systems/LevelGeneration/LevelGenerationRoot");
			if ((Object)(object)val2 == (Object)null)
			{
				if (((Object)StartOfRound.Instance.currentLevel).name != "CompanyBuildingLevel")
				{
					Plugin.Logger.LogWarning((object)"Landed on a moon with no dungeon generated. This shouldn't happen");
				}
				return;
			}
			Tile[] componentsInChildren = val2.GetComponentsInChildren<Tile>();
			foreach (Tile val3 in componentsInChildren)
			{
				if (((Object)val3).name.StartsWith("MineshaftStartTile"))
				{
					Vector3[] array = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(-16f, 41.37f, -4.3f),
						new Vector3(14f, 41.37f, -4.3f),
						new Vector3(-16f, 61.37f, -4.3f),
						new Vector3(14f, 61.37f, -4.3f),
						new Vector3(-16f, 41.37f, 10.7f),
						new Vector3(14f, 41.37f, 10.7f),
						new Vector3(-16f, 61.37f, 10.7f),
						new Vector3(14f, 61.37f, 10.7f)
					};
					((Component)val3).transform.TransformPoints((Span<Vector3>)array);
					Vector3 val4 = array[0];
					Vector3 val5 = array[0];
					for (int num2 = 1; num2 < array.Length; num2++)
					{
						val4 = Vector3.Min(val4, array[num2]);
						val5 = Vector3.Max(val5, array[num2]);
					}
					Bounds val6 = default(Bounds);
					((Bounds)(ref val6)).min = val4;
					((Bounds)(ref val6)).max = val5;
					mineStartBounds = val6;
					Plugin.Logger.LogDebug((object)"Calculated bounds for mineshaft elevator's start room");
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void GameNetworkManager_Post_Start()
		{
			RMNetworker.Init();
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void StartOfRound_Post_Awake()
		{
			RMNetworker.Create();
		}
	}
	internal static class RenderingOverrides
	{
		private static MapperScreen currentScreen;

		private static bool? lineNotRendering;

		private static bool? contourActive;

		private static float? contourAltitude;

		public static void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			ResetRendering();
			currentScreen = ((Component)camera).GetComponent<MapperScreen>();
			if (!((Object)(object)currentScreen != (Object)null))
			{
				return;
			}
			((Behaviour)currentScreen.light).enabled = true;
			currentScreen.transition.forceRenderingOff = false;
			((Renderer)currentScreen.line).forceRenderingOff = !currentScreen.drawPath;
			if (!((Object)(object)StartOfRound.Instance?.mapScreen != (Object)null))
			{
				return;
			}
			if ((Object)(object)currentScreen.target != (Object)null && currentScreen.target.isInHangarShipRoom)
			{
				camera.nearClipPlane = -0.96f;
				camera.farClipPlane = 7.52f;
			}
			else
			{
				camera.nearClipPlane = StartOfRound.Instance.mapScreen.cameraNearPlane;
				camera.farClipPlane = StartOfRound.Instance.mapScreen.cameraFarPlane;
				if (StartOfRound.Instance.currentLevelID != 3 && (((Object)(object)currentScreen.target != (Object)null) ? (!currentScreen.target.isInsideFactory) : (((Component)camera).transform.position.y >= -80f)))
				{
					camera.nearClipPlane -= 18f;
					camera.farClipPlane += 18f;
				}
			}
			if ((Object)(object)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit != (Object)null)
			{
				lineNotRendering = ((Renderer)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit).forceRenderingOff;
				((Renderer)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit).forceRenderingOff = true;
			}
			GameObject contourMap = StartOfRound.Instance.mapScreen.contourMap;
			if (!((Object)(object)contourMap != (Object)null) || !((Object)(object)currentScreen.target != (Object)null))
			{
				return;
			}
			bool flag = !currentScreen.target.isInsideFactory;
			float y = ((Component)camera).transform.position.y;
			if (currentScreen.target.isPlayerDead)
			{
				if ((Object)(object)currentScreen.target.redirectToEnemy != (Object)null)
				{
					Transform radarHeadTransform = currentScreen.target.redirectToEnemy.GetRadarHeadTransform();
					if ((Object)(object)radarHeadTransform != (Object)null)
					{
						y = radarHeadTransform.position.y;
					}
				}
				else if ((Object)(object)currentScreen.target.deadBody != (Object)null && ((Component)currentScreen.target.deadBody).gameObject.activeSelf && currentScreen.target.deadBody.bodyParts.Length != 0 && (Object)(object)currentScreen.target.deadBody.bodyParts[0] != (Object)null)
				{
					y = ((Component)currentScreen.target.deadBody.bodyParts[0]).transform.position.y;
				}
			}
			else if ((Object)(object)currentScreen.target.playerGlobalHead != (Object)null)
			{
				y = currentScreen.target.playerGlobalHead.position.y;
			}
			if (!flag && y > -80f)
			{
				flag = true;
			}
			if (flag)
			{
				contourActive = contourMap.activeSelf;
				contourAltitude = contourMap.transform.position.y;
				contourMap.transform.position = new Vector3(contourMap.transform.position.x, y - 1.5f, contourMap.transform.position.z);
				contourMap.SetActive(true);
			}
		}

		public static void OnEndCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			ResetRendering();
		}

		private static void ResetRendering()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (lineNotRendering.HasValue)
			{
				if ((Object)(object)StartOfRound.Instance?.mapScreen?.lineFromRadarTargetToExit != (Object)null)
				{
					((Renderer)StartOfRound.Instance.mapScreen.lineFromRadarTargetToExit).forceRenderingOff = lineNotRendering.Value;
				}
				lineNotRendering = null;
			}
			GameObject val = StartOfRound.Instance?.mapScreen?.contourMap;
			if (contourActive.HasValue)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(contourActive.Value);
				}
				contourActive = null;
			}
			if (contourAltitude.HasValue)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.transform.position = new Vector3(val.transform.position.x, contourAltitude.Value, val.transform.position.z);
				}
				contourAltitude = null;
			}
			if ((Object)(object)currentScreen != (Object)null)
			{
				((Behaviour)currentScreen.light).enabled = false;
				currentScreen.transition.forceRenderingOff = true;
				((Renderer)currentScreen.line).forceRenderingOff = true;
			}
		}
	}
	internal class RMNetworker : NetworkBehaviour
	{
		internal static GameObject prefab;

		internal static RMNetworker Instance { get; private set; }

		internal NetworkVariable<bool> ShowPath { get; private set; } = new NetworkVariable<bool>(false, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		internal NetworkVariable<int> Price { get; private set; } = new NetworkVariable<int>(0, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		internal NetworkVariable<float> BatteryUsage { get; private set; } = new NetworkVariable<float>(0f, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		internal static void Init()
		{
			//IL_0023: 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_0035: Expected O, but got Unknown
			if ((Object)(object)prefab != (Object)null)
			{
				Plugin.Logger.LogDebug((object)"Skipped network handler registration, because it has already been initialized");
				return;
			}
			try
			{
				prefab = new GameObject("RMNetworker")
				{
					hideFlags = (HideFlags)61
				};
				NetworkObject val = prefab.AddComponent<NetworkObject>();
				byte[] value = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(typeof(RMNetworker).Assembly.GetName().Name + ((Object)prefab).name + "1.5.0".ToString()));
				val.GlobalObjectIdHash = BitConverter.ToUInt32(value, 0);
				prefab.AddComponent<RMNetworker>();
				NetworkManager.Singleton.AddNetworkPrefab(prefab);
				Plugin.Logger.LogDebug((object)$"Successfully registered network handler (#{val.GlobalObjectIdHash})");
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Encountered some fatal error while registering network handler. The mod will not function like this!\n{arg}");
			}
		}

		internal static void Create()
		{
			try
			{
				if (NetworkManager.Singleton.IsServer && (Object)(object)prefab != (Object)null)
				{
					Object.Instantiate<GameObject>(prefab).GetComponent<NetworkObject>().Spawn(true);
				}
			}
			catch
			{
				Plugin.Logger.LogError((object)"Encountered some fatal error while spawning network handler. It is likely that registration failed earlier on start-up, please consult your logs.");
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if ((Object)(object)Instance != (Object)(object)this)
			{
				NetworkObject val = default(NetworkObject);
				if (((Component)Instance).TryGetComponent<NetworkObject>(ref val) && !val.IsSpawned && (Object)(object)Instance != (Object)(object)prefab)
				{
					Object.Destroy((Object)(object)Instance);
				}
				Plugin.Logger.LogWarning((object)"There are 2 RMNetworkers instantiated, and the wrong one was assigned as Instance. This shouldn't happen, but is recoverable");
				Instance = this;
			}
			Plugin.Logger.LogDebug((object)"Successfully spawned network handler.");
			OverrideOnAllClients();
		}

		private void Start()
		{
			if (!((Object)(object)this != (Object)(object)Instance) && ((NetworkBehaviour)this).IsSpawned && ((NetworkBehaviour)this).IsServer)
			{
				ShowPath.Value = Plugin.configShowPath.Value;
				Price.Value = Plugin.configPrice.Value;
				BatteryUsage.Value = Plugin.configBatteryUsage.Value;
				OverrideOnAllClients();
			}
		}

		private void OverrideOnAllClients()
		{
			Item val = (StartOfRound.Instance ?? Object.FindAnyObjectByType<StartOfRound>())?.allItemsList?.itemsList?.FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "MapDevice"));
			if ((Object)(object)val != (Object)null)
			{
				if (val.creditsWorth != Price.Value)
				{
					val.creditsWorth = Price.Value;
					Plugin.Logger.LogDebug((object)"Updated price");
				}
				if (val.batteryUsage != BatteryUsage.Value)
				{
					val.batteryUsage = Mathf.Clamp01(BatteryUsage.Value / 100f);
					Plugin.Logger.LogDebug((object)"Updated battery usage");
				}
			}
		}

		protected override void __initializeVariables()
		{
			if (ShowPath == null)
			{
				throw new Exception("RMNetworker.<ShowPath>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)ShowPath).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)ShowPath, "ShowPath");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)ShowPath);
			if (Price == null)
			{
				throw new Exception("RMNetworker.<Price>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)Price).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)Price, "Price");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)Price);
			if (BatteryUsage == null)
			{
				throw new Exception("RMNetworker.<BatteryUsage>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)BatteryUsage).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)BatteryUsage, "BatteryUsage");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)BatteryUsage);
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			((NetworkBehaviour)this).__initializeRpcs();
		}

		protected internal override string __getTypeName()
		{
			return "RMNetworker";
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RestoreMapper";

		public const string PLUGIN_NAME = "RestoreMapper";

		public const string PLUGIN_VERSION = "1.5.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
			NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
			NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
			NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<float>();
			NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<float>();
		}
	}
}
namespace RestoreMapper.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}