Decompiled source of NavMeshInCompanyRedux v1.0.0

plugins/TRizzle-NavMeshInCompanyRedux/NavMeshInCompanyRedux.dll

Decompiled 11 hours ago
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.AI.Navigation;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

[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("NavMeshInCompanyRedux")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e7fbaccda666e8b48254882298a872673cbf194e")]
[assembly: AssemblyProduct("NavMeshInCompanyRedux")]
[assembly: AssemblyTitle("NavMeshInCompanyRedux")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: TypeForwardedTo(typeof(AllowNullAttribute))]
[assembly: TypeForwardedTo(typeof(DisallowNullAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullWhenAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullIfNotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullWhenAttribute))]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 NavMeshInCompanyRedux
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "T-Rizzle.NavMeshInCompanyRedux";

		public const string PLUGIN_NAME = "NavMeshInCompanyRedux";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("T-Rizzle.NavMeshInCompanyRedux", "NavMeshInCompanyRedux", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string COMPANY_BUILDING_MOON_SCENE_NAME = "71 Gordion.CompanyBuilding";

		public static AssetBundle ModAssets;

		internal static string DirectoryName;

		internal static GameObject CompanyBuildingNavMeshPrefab;

		internal static ManualLogSource Logger;

		private readonly Harmony _harmony = new Harmony("T-Rizzle.NavMeshInCompanyRedux");

		private void Awake()
		{
			string path = "companybuildingnavmesh";
			DirectoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Logger = ((BaseUnityPlugin)this).Logger;
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(DirectoryName, path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogFatal((object)"Unknown to load custom assets.");
				return;
			}
			CompanyBuildingNavMeshPrefab = ModAssets.LoadAsset<GameObject>("CompanyBuildingNavMesh");
			if ((Object)(object)CompanyBuildingNavMeshPrefab == (Object)null)
			{
				Logger.LogFatal((object)"Failed to load the nav mesh prefab from the asset bundle.");
				return;
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
			Logger.LogInfo((object)"Plugin T-Rizzle.NavMeshInCompanyRedux is loaded!");
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.currentLevel == (Object)null)
			{
				return;
			}
			string text = instance.currentLevel.PlanetName + "." + instance.currentLevel.sceneName;
			if (text != "71 Gordion.CompanyBuilding")
			{
				return;
			}
			try
			{
				Logger.LogInfo((object)"Instantiating Company Navigation!");
				GameObject obj = GameObject.Find("CompanyBuildingNavMesh");
				Transform val = ((obj != null) ? obj.transform : null);
				if ((Object)(object)val == (Object)null)
				{
					GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
					for (int i = 0; i < array.Length; i++)
					{
						Object.Destroy((Object)(object)array[i]);
					}
					array = GameObject.FindGameObjectsWithTag("AINode");
					for (int j = 0; j < array.Length; j++)
					{
						Object.Destroy((Object)(object)array[j]);
					}
					val = Object.Instantiate<GameObject>(CompanyBuildingNavMeshPrefab).transform;
				}
				GameObject val2 = GameObject.Find("NavMeshColliders");
				if ((Object)(object)val2 != (Object)null)
				{
					Logger.LogInfo((object)"Found NavMeshColliders!");
					val.SetParent(val2.transform, true);
					val.position = val2.transform.position;
					val.rotation = val2.transform.rotation;
					Transform val3 = val2.transform.Find("PlayerShip");
					if ((Object)(object)val3 != (Object)null)
					{
						Logger.LogInfo((object)"Found old ShipNavmesh, destroying it!");
						Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
					}
					RoundManager instance2 = RoundManager.Instance;
					Transform val4 = val.Find("OutsideAINodes");
					instance2.outsideAINodes = (GameObject[])(object)new GameObject[val4.childCount];
					for (int k = 0; k < val4.childCount; k++)
					{
						instance2.outsideAINodes[k] = ((Component)val4.GetChild(k)).gameObject;
					}
					val4 = val.Find("InsideAINodes");
					instance2.insideAINodes = (GameObject[])(object)new GameObject[val4.childCount];
					for (int l = 0; l < val4.childCount; l++)
					{
						instance2.insideAINodes[l] = ((Component)val4.GetChild(l)).gameObject;
					}
					if (false)
					{
						NavMeshSurface[] componentsInChildren = ((Component)val).gameObject.GetComponentsInChildren<NavMeshSurface>(true);
						if (componentsInChildren == null || componentsInChildren.Length == 0)
						{
							Logger.LogError((object)"Failed to find any NavMeshSurface components on the instantiated prefab.");
							return;
						}
						NavMeshSurface[] array2 = componentsInChildren;
						foreach (NavMeshSurface val5 in array2)
						{
							bool enabled = ((Behaviour)val5).enabled;
							((Behaviour)val5).enabled = true;
							NavMeshData navMeshData = val5.navMeshData;
							if ((Object)(object)navMeshData != (Object)null)
							{
								val5.UpdateNavMesh(navMeshData);
							}
							else
							{
								val5.BuildNavMesh();
							}
							((Behaviour)val5).enabled = enabled;
						}
					}
					NavMeshLink[] componentsInChildren2 = ((Component)val).gameObject.GetComponentsInChildren<NavMeshLink>(true);
					NavMeshLink[] array3 = componentsInChildren2;
					foreach (NavMeshLink val6 in array3)
					{
						val6.UpdateLink();
					}
					OffMeshLink[] componentsInChildren3 = ((Component)val).gameObject.GetComponentsInChildren<OffMeshLink>(true);
					OffMeshLink[] array4 = componentsInChildren3;
					foreach (OffMeshLink val7 in array4)
					{
						val7.UpdatePositions();
					}
				}
				else
				{
					Logger.LogWarning((object)"Failed to find NavMeshColliders!");
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Exception occurred: {arg}");
			}
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}