Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of NavMeshInCompanyRedux v1.2.2
plugins/TRizzle-NavMeshInCompanyRedux/NavMeshInCompanyRedux.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CSync.Extensions; using CSync.Lib; 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: IgnoresAccessChecksTo("NavMeshInCompany")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("NavMeshInCompanyRedux")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.2.0")] [assembly: AssemblyInformationalVersion("1.2.2+89e2419f69c03f956ae9537a30084e8e4b404cd4")] [assembly: AssemblyProduct("NavMeshInCompanyRedux")] [assembly: AssemblyTitle("NavMeshInCompanyRedux")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.2.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 class Config : SyncedConfig2<Config> { private const string ConfigSection = "NavMeshInCompany Redux"; private const string ConfigDebug = "Debug"; [SyncedEntryField] public SyncedEntry<bool> EnableDynamicRegen; [SyncedEntryField] public SyncedEntry<bool> DeferedDynamicRegen; public ConfigEntry<bool> EnableDebugLog; public Config(ConfigFile cfg) : base("T-Rizzle.NavMeshInCompanyRedux") { cfg.SaveOnConfigSet = false; EnableDynamicRegen = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "NavMeshInCompany Redux", "Enable Dynamic Nav Regen", true, "Should the NavMesh be dynamically regenerated upon landing? \n The regeneration will be done asynchronously! \n This allows mod added buildings to added to the NavMesh at runtime."); DeferedDynamicRegen = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "NavMeshInCompany Redux", "Defer Dynamic Regen", true, "Some mod added buildings are spawned after the scene is loaded. This may cause the NavMesh regeneration to be too early. \n This option will tell dynamic regeneration to wait a short delay before regenerating the NavMesh."); EnableDebugLog = cfg.Bind<bool>("Debug", "EnableDebugLog (Client only)", false, "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(); } } [HarmonyPatch(typeof(DepositItemsDeskPatch))] public class NavMeshInCompanyPatch { [HarmonyPatch("StartPatch")] [HarmonyPrefix] public static bool StartPatch_Prefix() { return false; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "T-Rizzle.NavMeshInCompanyRedux"; public const string PLUGIN_NAME = "NavMeshInCompanyRedux"; public const string PLUGIN_VERSION = "1.2.0"; } [BepInPlugin("T-Rizzle.NavMeshInCompanyRedux", "NavMeshInCompanyRedux", "1.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] 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; public static Config Config; 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; Config = new Config(((BaseUnityPlugin)this).Config); 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; try { if (Chainloader.PluginInfos.ContainsKey("dev.kittenji.NavMeshInCompany")) { _harmony.PatchAll(typeof(NavMeshInCompanyPatch)); } } catch (Exception arg) { Logger.LogError((object)$"Failed to patch with error {arg}"); } Logger.LogInfo((object)"Plugin T-Rizzle.NavMeshInCompanyRedux is loaded!"); } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_030c: 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 { LogInfo("Instantiating Company Navigation!"); GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects(); if (rootGameObjects != null && rootGameObjects.Length != 0) { foreach (GameObject val in rootGameObjects) { if (!((Object)(object)val != (Object)null)) { continue; } MeshFilter[] componentsInChildren = val.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val2 in componentsInChildren) { if (!((Object)(object)val2 != (Object)null)) { continue; } int instanceID = ((Object)((Component)val2).gameObject).GetInstanceID(); string name = ((Object)((Component)val2).gameObject).name; if (name.Equals("Cube.005", StringComparison.InvariantCultureIgnoreCase)) { Mesh val3 = (val2.sharedMesh = ModAssets.LoadAsset<Mesh>("Cube.005")); MeshCollider component = ((Component)val2).gameObject.GetComponent<MeshCollider>(); if (component != null) { component.sharedMesh = val3; } LogDebug($"Replaced mesh for {name} with new mesh: {((Object)val3).name}. Read/Write {val3.isReadable}"); } else if (name.Equals("Cylinder", StringComparison.InvariantCultureIgnoreCase)) { Mesh val5 = (val2.sharedMesh = ModAssets.LoadAsset<Mesh>("Cylinder")); MeshCollider component2 = ((Component)val2).gameObject.GetComponent<MeshCollider>(); if (component2 != null) { component2.sharedMesh = val5; } LogDebug($"Replaced mesh for {name} with new mesh: {((Object)val5).name}. Read/Write {val5.isReadable}"); } else if (name.Equals("DrillPlatform", StringComparison.InvariantCultureIgnoreCase)) { Mesh val7 = (val2.sharedMesh = ModAssets.LoadAsset<Mesh>("DrillPlatform")); MeshCollider component3 = ((Component)val2).gameObject.GetComponent<MeshCollider>(); if (component3 != null) { component3.sharedMesh = val7; } LogDebug($"Replaced mesh for {name} with new mesh: {((Object)val7).name}. Read/Write {val7.isReadable}"); } else if (name.Equals("Elbow Joint.001", StringComparison.InvariantCultureIgnoreCase)) { Mesh val9 = (val2.sharedMesh = ModAssets.LoadAsset<Mesh>("Elbow Joint.001")); MeshCollider component4 = ((Component)val2).gameObject.GetComponent<MeshCollider>(); if (component4 != null) { component4.sharedMesh = val9; } LogDebug($"Replaced mesh for {name} with new mesh: {((Object)val9).name}. Read/Write {val9.isReadable}"); } } } } GameObject obj = GameObject.Find("CompanyBuildingNavMesh"); Transform val11 = ((obj != null) ? obj.transform : null); if ((Object)(object)val11 == (Object)null) { GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode"); for (int k = 0; k < array.Length; k++) { Object.Destroy((Object)(object)array[k]); } array = GameObject.FindGameObjectsWithTag("AINode"); for (int l = 0; l < array.Length; l++) { Object.Destroy((Object)(object)array[l]); } val11 = ((GameObject)Object.Instantiate((Object)(object)CompanyBuildingNavMeshPrefab, scene)).transform; } GameObject val12 = ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject x) => ((Object)x).name.Equals("Environment", StringComparison.InvariantCultureIgnoreCase))); Transform val13 = (((Object)(object)val12 != (Object)null) ? val12.transform.Find("NavMeshColliders") : null); if ((Object)(object)val13 != (Object)null) { LogInfo("Found NavMeshColliders!"); Transform val14 = val13.Find("PlayerShip"); val11.position = ((Component)val13).transform.position; val11.rotation = ((Component)val13).transform.rotation; if ((Object)(object)val14 != (Object)null) { LogInfo("Found old ShipNavmesh, destroying it!"); Object.DestroyImmediate((Object)(object)((Component)val14).gameObject); } } else { val11.position = new Vector3(-17.438856f, 7.6053805f, -16.471304f); val11.rotation = Quaternion.identity; LogWarning("Failed to find NavMeshColliders!"); } RoundManager instance2 = RoundManager.Instance; Transform val15 = val11.Find("OutsideAINodes"); instance2.outsideAINodes = (GameObject[])(object)new GameObject[val15.childCount]; for (int num = 0; num < val15.childCount; num++) { instance2.outsideAINodes[num] = ((Component)val15.GetChild(num)).gameObject; } val15 = val11.Find("InsideAINodes"); instance2.insideAINodes = (GameObject[])(object)new GameObject[val15.childCount]; for (int num2 = 0; num2 < val15.childCount; num2++) { instance2.insideAINodes[num2] = ((Component)val15.GetChild(num2)).gameObject; } if (Config.EnableDynamicRegen.Value) { NavMeshSurface[] componentsInChildren2 = ((Component)val11).gameObject.GetComponentsInChildren<NavMeshSurface>(true); if (componentsInChildren2 == null || componentsInChildren2.Length == 0) { LogError("Failed to find any NavMeshSurface components on the instantiated prefab."); } else { ((MonoBehaviour)instance2).StartCoroutine(UpdateNavmeshDelayed(val11, componentsInChildren2)); } return; } NavMeshLink[] componentsInChildren3 = ((Component)val11).gameObject.GetComponentsInChildren<NavMeshLink>(true); NavMeshLink[] array2 = componentsInChildren3; foreach (NavMeshLink val16 in array2) { val16.UpdateLink(); } OffMeshLink[] componentsInChildren4 = ((Component)val11).gameObject.GetComponentsInChildren<OffMeshLink>(true); OffMeshLink[] array3 = componentsInChildren4; foreach (OffMeshLink val17 in array3) { val17.UpdatePositions(); } } catch (Exception arg) { Logger.LogError((object)$"Exception occurred: {arg}"); } } private static IEnumerator UpdateNavmeshDelayed(Transform? companyTransform, NavMeshSurface[] surfacesToRebake) { if (Config.DeferedDynamicRegen.Value) { LogDebug("Waiting 1 second before rebaking the navmesh to allow any mod added buildings to be spawned."); yield return (object)new WaitForSeconds(1f); } foreach (NavMeshSurface navMeshSurface in surfacesToRebake) { if ((Object)(object)navMeshSurface != (Object)null) { LogDebug($"Updating NavMesh for surface {((Object)((Component)navMeshSurface).gameObject).name} with {((Component)navMeshSurface).GetComponentsInChildren<NavMeshModifierVolume>().Length} modifiers."); bool wasEnabled = ((Behaviour)navMeshSurface).enabled; ((Behaviour)navMeshSurface).enabled = true; NavMeshData navMeshData = navMeshSurface.navMeshData; if ((Object)(object)navMeshData != (Object)null) { AsyncOperation asyncOperation = navMeshSurface.UpdateNavMesh(navMeshData); while (asyncOperation != null && !asyncOperation.isDone) { yield return null; } } else { navMeshSurface.BuildNavMesh(); } LogDebug("UpdateNavMesh finished, refreshing surface data."); navMeshSurface.RemoveData(); LogDebug("Removed existing data."); if (wasEnabled) { navMeshSurface.AddData(); LogDebug("Added updated data."); } ((Behaviour)navMeshSurface).enabled = wasEnabled; } else { LogWarning("Found a null NavMeshSurface in the list to rebake, skipping it."); } } if (Object.op_Implicit((Object)(object)companyTransform)) { NavMeshLink[] componentsInChildren = ((Component)companyTransform).gameObject.GetComponentsInChildren<NavMeshLink>(true); NavMeshLink[] array = componentsInChildren; foreach (NavMeshLink val in array) { val.UpdateLink(); } OffMeshLink[] componentsInChildren2 = ((Component)companyTransform).gameObject.GetComponentsInChildren<OffMeshLink>(true); OffMeshLink[] array2 = componentsInChildren2; foreach (OffMeshLink val2 in array2) { val2.UpdatePositions(); } } LogDebug("Updated all given NavMeshes."); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void LogDebug(string debugLog) { if (Config.EnableDebugLog.Value) { 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 System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } } 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; } } }