Decompiled source of LethalBotsNavMeshProject v1.0.0

plugins/TRizzle-LethalBots NavMesh Project/LethalBotsNavMeshProject.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using HarmonyLib;
using LethalBotsNavMeshProject.MoonNavMeshes;
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("LethalBotsNavMeshProject")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ffd0253180d181833dc6fc8fe91a1ee4db49373f")]
[assembly: AssemblyProduct("LethalBotsNavMeshProject")]
[assembly: AssemblyTitle("LethalBotsNavMeshProject")]
[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]
	[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 LethalBotsNavMeshProject
{
	public class Config : SyncedConfig2<Config>
	{
		private const string ConfigSection = "Lethal Bots NavMesh Project";

		private const string ConfigDebug = "Debug";

		[SyncedEntryField]
		public SyncedEntry<bool> EnableExperimentationNav;

		[SyncedEntryField]
		public SyncedEntry<bool> EnableAssuranceNav;

		[SyncedEntryField]
		public SyncedEntry<bool> EnableVowNav;

		[SyncedEntryField]
		public SyncedEntry<bool> EnableOffenceNav;

		[SyncedEntryField]
		public SyncedEntry<bool> EnableAdamanceNav;

		[SyncedEntryField]
		public SyncedEntry<bool> EnableEmbrionNav;

		public ConfigEntry<bool> EnableDebugLog;

		public Config(ConfigFile cfg)
			: base("T-Rizzle.LethalBotsNavMeshProject")
		{
			cfg.SaveOnConfigSet = false;
			EnableExperimentationNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Experimentation Nav Improvements", true, "If you are using a modified version of Experimentation, you may want to disable these improvements!");
			EnableAssuranceNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Assurance Nav Improvements", true, "If you are using a modified version of Assurance, you may want to disable these improvements!");
			EnableVowNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Vow Nav Improvements", true, "If you are using a modified version of Vow, you may want to disable these improvements!");
			EnableOffenceNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Offence Nav Improvements", true, "If you are using a modified version of Offence, you may want to disable these improvements!");
			EnableAdamanceNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Adamance Nav Improvements", true, "If you are using a modified version of Adamance, you may want to disable these improvements!");
			EnableEmbrionNav = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Lethal Bots NavMesh Project", "Enable Embrion Nav Improvements", true, "If you are using a modified version of Embrion, you may want to disable these improvements!");
			EnableDebugLog = cfg.Bind<bool>("Debug", "EnableDebugLog  (Client only)", true, "Enable the debug logs used for this mod.");
			ClearUnusedEntries(cfg);
			cfg.SaveOnConfigSet = true;
		}

		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
	public static class NavMeshPrefabManager
	{
		private const string EXPERIMENTATION_MOON_SCENE_NAME = "41 Experimentation.Level1Experimentation";

		private const string ASSURANCE_MOON_SCENE_NAME = "220 Assurance.Level2Assurance";

		private const string VOW_MOON_SCENE_NAME = "56 Vow.Level3Vow";

		private const string OFFENSE_MOON_SCENE_NAME = "21 Offense.Level7Offense";

		private const string ADAMANCE_MOON_SCENE_NAME = "20 Adamance.Level10Adamance";

		private const string EMBRION_MOON_SCENE_NAME = "5 Embrion.Level11Embrion";

		public static readonly Dictionary<string, MoonNavMesh> NavMeshPrefabs = new Dictionary<string, MoonNavMesh>();

		private static GameObject ExperimentationNavPrefab = null;

		private static GameObject AssuranceNavPrefab = null;

		private static GameObject VowNavPrefab = null;

		private static GameObject OffenseNavPrefab = null;

		private static GameObject AdamanceNavPrefab = null;

		private static GameObject EmbrionNavPrefab = null;

		internal static void LoadPrefabs()
		{
			if (!ArePrefabsLoaded())
			{
				ExperimentationNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("ExperimentationNavMesh");
				AssuranceNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("AssuranceNavMesh");
				VowNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("VowNavMesh");
				OffenseNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("OffenseNavMesh");
				AdamanceNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("AdamanceNavMesh");
				EmbrionNavPrefab = Plugin.ModAssets.LoadAsset<GameObject>("EmbrionNavMesh");
			}
			NavMeshPrefabs.Clear();
			NavMeshPrefabs.TryAdd("41 Experimentation.Level1Experimentation", new ExperimentationNavMesh(ExperimentationNavPrefab));
			NavMeshPrefabs.TryAdd("220 Assurance.Level2Assurance", new AssuranceNavMesh(AssuranceNavPrefab));
			NavMeshPrefabs.TryAdd("56 Vow.Level3Vow", new VowNavMesh(VowNavPrefab));
			NavMeshPrefabs.TryAdd("21 Offense.Level7Offense", new OffenceNavMesh(OffenseNavPrefab));
			NavMeshPrefabs.TryAdd("20 Adamance.Level10Adamance", new AdamanceNavMesh(AdamanceNavPrefab));
			NavMeshPrefabs.TryAdd("5 Embrion.Level11Embrion", new EmbrionNavMesh(EmbrionNavPrefab));
		}

		public static GameObject? GetPrefabForLevel(string levelName)
		{
			if (!NavMeshPrefabs.TryGetValue(levelName, out MoonNavMesh value))
			{
				Plugin.LogError("No navmesh prefab found for level with scene name: " + levelName);
				return null;
			}
			return value.GetNavPrefab();
		}

		public static bool IsValidLevel(string levelName)
		{
			if (NavMeshPrefabs.TryGetValue(levelName, out MoonNavMesh value))
			{
				return value.IsPrefabEnabled();
			}
			return false;
		}

		public static bool ArePrefabsLoaded()
		{
			if ((Object)(object)ExperimentationNavPrefab != (Object)null && (Object)(object)AssuranceNavPrefab != (Object)null && (Object)(object)VowNavPrefab != (Object)null && (Object)(object)OffenseNavPrefab != (Object)null && (Object)(object)AdamanceNavPrefab != (Object)null)
			{
				return (Object)(object)EmbrionNavPrefab != (Object)null;
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "T-Rizzle.LethalBotsNavMeshProject";

		public const string PLUGIN_NAME = "LethalBotsNavMeshProject";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("T-Rizzle.LethalBotsNavMeshProject", "LethalBotsNavMeshProject", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle ModAssets;

		internal static string DirectoryName;

		internal static ManualLogSource Logger;

		internal static Config Config;

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

		private void Awake()
		{
			string path = "lethalbotsnavmesh";
			DirectoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Logger = ((BaseUnityPlugin)this).Logger;
			Config = new Config(((BaseUnityPlugin)this).Config);
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(DirectoryName, path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				LogFatal("Failed to load custom assets.");
				return;
			}
			NavMeshPrefabManager.LoadPrefabs();
			if (!NavMeshPrefabManager.ArePrefabsLoaded())
			{
				LogWarning("Failed to load some or all of the nav mesh prefabs from the asset bundle.");
				LogWarning("Some levels may not have custom nav meshes.");
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
			LogInfo("Plugin T-Rizzle.LethalBotsNavMeshProject is loaded!");
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.currentLevel == (Object)null)
			{
				return;
			}
			string levelName = instance.currentLevel.PlanetName + "." + instance.currentLevel.sceneName;
			if (!NavMeshPrefabManager.IsValidLevel(levelName))
			{
				return;
			}
			try
			{
				LogInfo("Instantiating NavMesh prefab for moon: " + instance.currentLevel.PlanetName + " with scene name " + instance.currentLevel.sceneName);
				GameObject prefabForLevel = NavMeshPrefabManager.GetPrefabForLevel(levelName);
				if ((Object)(object)prefabForLevel == (Object)null)
				{
					LogError("Failed to get navmesh prefab for level with scene name " + instance.currentLevel.sceneName);
					return;
				}
				Transform val = null;
				GameObject val2 = GameObject.Find("Environment");
				if ((Object)(object)val2 == (Object)null)
				{
					LogError("Failed to find Environment object in the scene!");
					return;
				}
				Transform val3 = val2.transform.Find("NavMeshColliders");
				if ((Object)(object)val3 == (Object)null)
				{
					LogWarning("Failed to find NavMeshColliders! Fallback to parenting to the Environment object.");
					val = val2.transform;
				}
				else
				{
					val = val3;
				}
				GameObject val4 = Object.Instantiate<GameObject>(prefabForLevel, val);
				NavMeshLink[] componentsInChildren = val4.GetComponentsInChildren<NavMeshLink>(true);
				NavMeshLink[] array = componentsInChildren;
				foreach (NavMeshLink val5 in array)
				{
					val5.area = 29;
					val5.UpdateLink();
				}
				OffMeshLink[] componentsInChildren2 = val4.GetComponentsInChildren<OffMeshLink>(true);
				OffMeshLink[] array2 = componentsInChildren2;
				foreach (OffMeshLink val6 in array2)
				{
					val6.area = 29;
					val6.UpdatePositions();
				}
			}
			catch (Exception arg)
			{
				LogError($"Exception occurred: {arg}");
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogDebug(string debugLog)
		{
			Logger.LogDebug((object)debugLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogInfo(string infoLog)
		{
			Logger.LogInfo((object)infoLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogWarning(string warningLog)
		{
			Logger.LogWarning((object)warningLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogError(string errorLog)
		{
			Logger.LogError((object)errorLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogFatal(string errorLog)
		{
			Logger.LogFatal((object)errorLog);
		}
	}
}
namespace LethalBotsNavMeshProject.MoonNavMeshes
{
	public class AdamanceNavMesh : MoonNavMesh
	{
		internal AdamanceNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableAdamanceNav);
		}
	}
	public class AssuranceNavMesh : MoonNavMesh
	{
		internal AssuranceNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableAssuranceNav);
		}
	}
	public class EmbrionNavMesh : MoonNavMesh
	{
		internal EmbrionNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableEmbrionNav);
		}
	}
	public class ExperimentationNavMesh : MoonNavMesh
	{
		internal ExperimentationNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableExperimentationNav);
		}
	}
	public abstract class MoonNavMesh
	{
		protected GameObject? navPrefab;

		public virtual bool IsPrefabEnabled()
		{
			return true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public GameObject? GetNavPrefab()
		{
			return navPrefab;
		}
	}
	internal class OffenceNavMesh : MoonNavMesh
	{
		internal OffenceNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableOffenceNav);
		}
	}
	public class VowNavMesh : MoonNavMesh
	{
		internal VowNavMesh(GameObject prefab)
		{
			navPrefab = prefab;
		}

		public override bool IsPrefabEnabled()
		{
			return SyncedEntry<bool>.op_Implicit(Plugin.Config.EnableVowNav);
		}
	}
}
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;
		}
	}
}