Decompiled source of NavigatingStars v0.0.4

plugins/NavigatingStars.dll

Decompiled 2 months ago
using System;
using System.Collections;
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.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompany.Mods;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NavigatingStars")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NavigatingStars")]
[assembly: AssemblyTitle("NavigatingStars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalCompany.Mods
{
	public class PluginConfig
	{
		public static ConfigEntry<Key>? ToggleKey;

		public static ConfigEntry<float>? LineWidth;

		public static ConfigEntry<Color>? LineColor;

		public static ConfigEntry<float>? AutoClearDistance;

		public static ConfigEntry<bool>? DynamicLineRedraw;

		public static ConfigEntry<bool>? EnableSoundEffects;

		public static ConfigEntry<float>? SoundEffectVolume;

		public static ConfigEntry<bool>? Enable3DSound;

		public static void BindConfig(ConfigFile config)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			ToggleKey = config.Bind<Key>("General", "ToggleKey", (Key)34, "The key to press for drawing the line.");
			LineWidth = config.Bind<float>("General", "LineWidth", 0.1f, "The width of the drawn line.");
			LineColor = config.Bind<Color>("General", "LineColor", Color.green, "The color of the drawn line.");
			AutoClearDistance = config.Bind<float>("General", "AutoClearDistance", 2.5f, "The distance threshold for auto-clearing the line when the player is near the main entrance.");
			DynamicLineRedraw = config.Bind<bool>("General", "DynamicLineRedraw", true, "Determines whether the line should be redrawn dynamically based on the player's position.");
			EnableSoundEffects = config.Bind<bool>("Sound", "EnableSoundEffects", true, "Determines whether sound effects are enabled or disabled.");
			SoundEffectVolume = config.Bind<float>("Sound", "SoundEffectVolume", 1f, "The volume of the sound effects (0f to 1f).");
			Enable3DSound = config.Bind<bool>("Sound", "Enable3DSound", true, "Determines whether 3D sound is enabled or disabled.");
		}
	}
	public class PathDrawer : MonoBehaviour
	{
		private SoundManager? soundManager;

		private LineRenderer? lineRenderer;

		private Key toggleKey;

		private Vector3 mainEntrancePosition;

		private Vector3 previousNearestNodePosition;

		private GameObject? playerObject;

		private const float SimplifyTolerance = 0.01f;

		private bool isLineDrawn = false;

		private Coroutine? drawLineCoroutine;

		private NavMeshManager? navMeshManager;

		private AINodeManager? aiNodeManager;

		private void Start()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0049: 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_00a9: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			lineRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>();
			((Renderer)lineRenderer).material = new Material(Shader.Find("Sprites/Default"))
			{
				color = PluginConfig.LineColor.Value
			};
			lineRenderer.startColor = PluginConfig.LineColor.Value;
			lineRenderer.endColor = PluginConfig.LineColor.Value;
			lineRenderer.startWidth = PluginConfig.LineWidth.Value;
			lineRenderer.endWidth = PluginConfig.LineWidth.Value;
			((Renderer)lineRenderer).enabled = false;
			toggleKey = PluginConfig.ToggleKey.Value;
			navMeshManager = new NavMeshManager();
			aiNodeManager = new AINodeManager();
			soundManager = Object.FindObjectOfType<SoundManager>();
			if ((Object)(object)soundManager == (Object)null)
			{
				GameObject val = new GameObject("SoundManager");
				soundManager = val.AddComponent<SoundManager>();
			}
			if ((Object)(object)soundManager != (Object)null)
			{
				soundManager.EnableSoundEffects = PluginConfig.EnableSoundEffects.Value;
				soundManager.SoundEffectVolume = PluginConfig.SoundEffectVolume.Value;
				soundManager.Enable3DSound = PluginConfig.Enable3DSound.Value;
			}
		}

		private void Update()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			bool isPlayerOutside = (Object)(object)val != (Object)null && !val.isInsideFactory;
			aiNodeManager.UpdateAINodesReference(isPlayerOutside);
			if (isLineDrawn)
			{
				float num = Vector3.Distance(playerObject.transform.position, mainEntrancePosition);
				if (num <= PluginConfig.AutoClearDistance.Value * PluginConfig.AutoClearDistance.Value)
				{
					ClearLine();
					navMeshManager.EnableNavMeshAgent();
					isLineDrawn = false;
				}
				else if (PluginConfig.DynamicLineRedraw.Value)
				{
					UpdateLineSegments();
				}
			}
			if (!((ButtonControl)Keyboard.current[toggleKey]).wasPressedThisFrame)
			{
				return;
			}
			Debug.Log((object)"Toggle key pressed!");
			playerObject = navMeshManager.FindPlayer();
			if ((Object)(object)playerObject == (Object)null)
			{
				return;
			}
			if ((Object)(object)playerObject != (Object)null)
			{
				if (isLineDrawn)
				{
					ClearLine();
					navMeshManager.EnableNavMeshAgent();
					isLineDrawn = false;
					return;
				}
				isPlayerOutside = IsPlayerOutside();
				Vector3 position = playerObject.transform.position;
				mainEntrancePosition = RoundManager.Instance.GetNavMeshPosition(RoundManager.FindMainEntrancePosition(true, isPlayerOutside), default(NavMeshHit), 5f, -1);
				Debug.Log((object)$"Main Entrance Position: {mainEntrancePosition}");
				NavMeshPath val2 = new NavMeshPath();
				if (NavMesh.CalculatePath(position, mainEntrancePosition, -1, val2))
				{
					if (drawLineCoroutine != null)
					{
						((MonoBehaviour)this).StopCoroutine(drawLineCoroutine);
					}
					drawLineCoroutine = ((MonoBehaviour)this).StartCoroutine(DrawLineAnimation(val2));
					isLineDrawn = true;
					((Renderer)lineRenderer).enabled = true;
					navMeshManager.DisableNavMeshAgent();
					Debug.Log((object)"Line renderer enabled.");
				}
				else
				{
					Debug.LogWarning((object)"No valid path found!");
					HUDManager val3 = Object.FindObjectOfType<HUDManager>();
					if ((Object)(object)val3 != (Object)null)
					{
						val3.DisplayTip("Path Not Found", "No valid path to the main entrance was found. Please try again or contact support.", true, false, "LC_Tip1");
					}
				}
			}
			else
			{
				Debug.LogWarning((object)"Player not found!");
			}
		}

		private IEnumerator DrawLineAnimation(NavMeshPath path)
		{
			if ((Object)(object)playerObject == (Object)null)
			{
				Debug.LogWarning((object)"Player not found!");
				yield break;
			}
			Vector3 playerPosition = playerObject.transform.position;
			Vector3[] pathCorners = path.corners;
			float segmentDuration = 0.1f;
			float animationDuration = (float)(pathCorners.Length - 1) * segmentDuration;
			float elapsedTime = 0f;
			lineRenderer.positionCount = pathCorners.Length + 1;
			lineRenderer.SetPosition(0, playerPosition);
			lineRenderer.SetPositions(pathCorners);
			((Renderer)lineRenderer).enabled = true;
			Vector3[] currentPositions2 = (Vector3[])(object)new Vector3[2]
			{
				playerPosition,
				pathCorners[0]
			};
			lineRenderer.positionCount = 2;
			lineRenderer.SetPositions(currentPositions2);
			int currentSegmentCount = 1;
			while (elapsedTime < animationDuration)
			{
				float t = elapsedTime / animationDuration;
				float easedT = EaseInOutCubic(t);
				int newSegmentCount2 = Mathf.RoundToInt(easedT * (float)(pathCorners.Length - 1)) + 1;
				newSegmentCount2 = Mathf.Clamp(newSegmentCount2, 2, pathCorners.Length + 1);
				if (newSegmentCount2 != currentSegmentCount)
				{
					currentSegmentCount = newSegmentCount2;
					currentPositions2 = (Vector3[])(object)new Vector3[currentSegmentCount + 1];
					currentPositions2[0] = playerPosition;
					Array.Copy(pathCorners, 0, currentPositions2, 1, currentSegmentCount);
					lineRenderer.positionCount = currentSegmentCount + 1;
					lineRenderer.SetPositions(currentPositions2);
					if (currentSegmentCount > 1 && PluginConfig.EnableSoundEffects.Value)
					{
						Vector3 segmentPosition = currentPositions2[currentSegmentCount];
						soundManager.PlaySound(segmentPosition);
					}
				}
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			if (!PluginConfig.DynamicLineRedraw.Value)
			{
				mainEntrancePosition = pathCorners[^1];
			}
			lineRenderer.Simplify(0.01f);
		}

		private float EaseInOutCubic(float t)
		{
			return (t < 0.5f) ? (4f * t * t * t) : (1f - Mathf.Pow(-2f * t + 2f, 3f) / 2f);
		}

		private bool IsPlayerOutside()
		{
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			return (Object)(object)val != (Object)null && !val.isInsideFactory;
		}

		private void UpdateLineSegments()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0084: 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_0101: 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)
			if (!isLineDrawn)
			{
				return;
			}
			if ((Object)(object)playerObject == (Object)null)
			{
				Debug.LogWarning((object)"Player not found!");
				return;
			}
			Vector3 position = playerObject.transform.position;
			Vector3 val = aiNodeManager.FindNearestAINodePosition(position);
			if (val != previousNearestNodePosition)
			{
				Vector3 val2 = val;
				Debug.Log((object)("Nearest AI Node Position: " + ((object)(Vector3)(ref val2)).ToString()));
				previousNearestNodePosition = val;
			}
			NavMeshPath val3 = new NavMeshPath();
			if (NavMesh.CalculatePath(val, mainEntrancePosition, -1, val3))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[lineRenderer.positionCount];
				if (array == null || array.Length == 0)
				{
					Debug.LogError((object)"Invalid path corners found!");
					return;
				}
				int cornersNonAlloc = val3.GetCornersNonAlloc(array);
				lineRenderer.positionCount = cornersNonAlloc + 1;
				lineRenderer.SetPosition(0, position);
				for (int i = 0; i < cornersNonAlloc; i++)
				{
					lineRenderer.SetPosition(i + 1, array[i]);
				}
				lineRenderer.Simplify(0.01f);
			}
			else
			{
				Debug.LogWarning((object)"No valid path found!");
			}
		}

		public void ClearLine()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (drawLineCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(drawLineCoroutine);
				drawLineCoroutine = null;
			}
			lineRenderer.positionCount = 0;
			mainEntrancePosition = Vector3.zero;
			previousNearestNodePosition = Vector3.zero;
			((Renderer)lineRenderer).enabled = false;
		}
	}
	public class SoundManager : MonoBehaviour
	{
		private AudioSource? audioSource;

		private AudioClip? lineDrawingSound;

		public static SoundManager? Instance { get; private set; }

		public bool EnableSoundEffects { get; set; }

		public float SoundEffectVolume { get; set; }

		public bool Enable3DSound { get; set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			LoadAudioResources();
		}

		private void LoadAudioResources()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream("NavigatingStars.Resources.line_drawing_sound.wav");
			if (stream != null)
			{
				int num = (int)(stream.Length / 2);
				float[] array = new float[num];
				byte[] array2 = new byte[2];
				for (int i = 0; i < num; i++)
				{
					stream.Read(array2, 0, 2);
					short num2 = BitConverter.ToInt16(array2, 0);
					array[i] = (float)num2 / 32768f;
				}
				lineDrawingSound = AudioClip.Create("LineDrawingSound", num, 1, 22050, false);
				lineDrawingSound.SetData(array, 0);
			}
			else
			{
				Debug.LogError((object)"Failed to load line drawing sound resource.");
			}
		}

		private AudioClip CreateAudioClip(byte[] audioData, string name)
		{
			int num = 1;
			int num2 = 22050;
			int num3 = audioData.Length / 2;
			AudioClip val = AudioClip.Create(name, num3, num, num2, false);
			float[] array = new float[num3];
			for (int i = 0; i < num3; i++)
			{
				short num4 = BitConverter.ToInt16(audioData, i * 2);
				array[i] = (float)num4 / 32768f;
			}
			val.SetData(array, 0);
			return val;
		}

		public void PlaySound(Vector3 position)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (EnableSoundEffects && (Object)(object)lineDrawingSound != (Object)null)
			{
				audioSource.Stop();
				audioSource.clip = lineDrawingSound;
				audioSource.spatialBlend = (Enable3DSound ? 1f : 0f);
				audioSource.volume = SoundEffectVolume;
				((Component)audioSource).transform.position = position;
				audioSource.Play();
			}
		}
	}
	public class NavMeshManager
	{
		private NavMeshAgent? navMeshAgent;

		public GameObject? FindPlayer()
		{
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val != (Object)null)
			{
				GameObject gameObject = ((Component)val).gameObject;
				navMeshAgent = gameObject.GetComponentInChildren<NavMeshAgent>();
				if ((Object)(object)navMeshAgent == (Object)null)
				{
					CreateNavMeshAgent(gameObject);
				}
				Debug.Log((object)("Player found: " + ((Object)gameObject).name));
				return gameObject;
			}
			Debug.LogWarning((object)"Player not found!");
			return null;
		}

		private void CreateNavMeshAgent(GameObject playerObject)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("NavMeshAgent");
			val.transform.SetParent(playerObject.transform);
			navMeshAgent = val.AddComponent<NavMeshAgent>();
		}

		public void EnableNavMeshAgent()
		{
			((Behaviour)navMeshAgent).enabled = true;
		}

		public void DisableNavMeshAgent()
		{
			((Behaviour)navMeshAgent).enabled = false;
		}
	}
	public class AINodeManager
	{
		private GameObject[] insideAINodes;

		private GameObject[] outsideAINodes;

		private bool isPlayerOutside;

		public AINodeManager()
		{
			insideAINodes = GameObject.FindGameObjectsWithTag("AINode");
			outsideAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
			Debug.Log((object)("Inside AI Nodes found: " + insideAINodes.Length));
			Debug.Log((object)("Outside AI Nodes found: " + outsideAINodes.Length));
		}

		public void UpdateAINodesReference(bool isPlayerOutside)
		{
			this.isPlayerOutside = isPlayerOutside;
		}

		public Vector3 FindNearestAINodePosition(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			GameObject[] array = (isPlayerOutside ? outsideAINodes : insideAINodes);
			if (array == null || array.Length == 0)
			{
				return position;
			}
			GameObject val = array.OrderBy((GameObject node) => Vector3.Distance(position, node.transform.position)).First();
			return val.transform.position;
		}
	}
}
namespace NavigatingStars
{
	[BepInPlugin("com.nilaier.navigatingstars", "Navigating Stars", "0.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.nilaier.navigatingstars";

		public const string PLUGIN_NAME = "Navigating Stars";

		public const string PLUGIN_VERSION = "0.0.4";

		private Harmony harmony = new Harmony("com.nilaier.navigatingstars");

		private void Awake()
		{
			harmony.PatchAll(typeof(Plugin));
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Navigating Stars v0.0.4 is loaded!");
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			string[] array = new string[7] { "InitScene", "InitSceneLaunchOptions", "InitSceneLANMode", "ColdOpen1", "MainMenu", "SampleSceneRelay", "CompanyBuilding" };
			if (Array.IndexOf(array, ((Scene)(ref scene)).name) != -1)
			{
				return;
			}
			EntranceTeleport val = RoundManager.FindMainEntranceScript(true);
			if ((Object)(object)val != (Object)null)
			{
				PlayerControllerB playerControllerB = PlayerUtils.GetPlayerControllerB();
				PathDrawer pathDrawer = default(PathDrawer);
				if ((Object)(object)playerControllerB != (Object)null && !((Component)playerControllerB).gameObject.TryGetComponent<PathDrawer>(ref pathDrawer))
				{
					((Component)playerControllerB).gameObject.AddComponent<PathDrawer>();
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		public static void PlayerUpdate(PlayerControllerB __instance)
		{
			PathDrawer pathDrawer = default(PathDrawer);
			if ((Object)(object)__instance == (Object)(object)PlayerUtils.GetPlayerControllerB() && !((Component)__instance).gameObject.TryGetComponent<PathDrawer>(ref pathDrawer))
			{
				((Component)__instance).gameObject.AddComponent<PathDrawer>();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ResetPlayersLoadedValueClientRpc")]
		[HarmonyPostfix]
		public static void ClearPathDrawersOnNewMap()
		{
			PlayerControllerB playerControllerB = PlayerUtils.GetPlayerControllerB();
			PathDrawer pathDrawer = default(PathDrawer);
			if ((Object)(object)playerControllerB != (Object)null && ((Component)playerControllerB).gameObject.TryGetComponent<PathDrawer>(ref pathDrawer))
			{
				pathDrawer.ClearLine();
			}
		}
	}
	public static class PlayerUtils
	{
		private static PlayerControllerB? localPlayerController;

		public static PlayerControllerB? GetPlayerControllerB()
		{
			if ((Object)(object)localPlayerController == (Object)null)
			{
				if ((Object)(object)GameNetworkManager.Instance != (Object)null)
				{
					localPlayerController = GameNetworkManager.Instance.localPlayerController;
					PlayerControllerB? obj = localPlayerController;
					Debug.Log((object)("[Navigating Stars] GetPlayerControllerB returned: " + (((obj != null) ? ((Object)obj).name : null) ?? "null")));
				}
				else
				{
					Debug.LogError((object)"[Navigating Stars] GameNetworkManager.Instance is null.");
				}
			}
			return localPlayerController;
		}
	}
}