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 StarlancerAIFix v3.12.0
StarlancerAI.dll
Decompiled a week agousing System; 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.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using StarlancerAIFix.Patches; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; [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("StarlancerAI")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+7e2ad66ec0d8c4582b559b365df0192b8209448a")] [assembly: AssemblyProduct("StarlancerAI")] [assembly: AssemblyTitle("StarlancerAI")] [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 StarlancerAIFix { [BepInPlugin("AudioKnight.StarlancerAIFix", "Starlancer AI Fix", "3.12.0")] public class StarlancerAIFixBase : BaseUnityPlugin { private const string modGUID = "AudioKnight.StarlancerAIFix"; private const string modName = "Starlancer AI Fix"; private const string modVersion = "3.12.0"; private readonly Harmony harmony = new Harmony("AudioKnight.StarlancerAIFix"); public static StarlancerAIFixBase Instance; internal static ManualLogSource logger; internal static ConfigFile AIFixConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, "AudioKnight.StarlancerAIFix.cfg"), true); public static ConfigEntry<bool> configLootBugHives; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } configLootBugHives = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hoarding Bugs Grab Hives", false, "Whether or not Hoarding Bugs can pick up Circuit Bee Hives. This has no effect on the following moons:\n--- Wesley's 58 Hyve \n--- Generic's 72 Collateral"); logger = ((BaseUnityPlugin)this).Logger; logger.LogInfo((object)"Starlancer AI Fix Online."); harmony.PatchAll(typeof(StarlancerAIFixBase)); harmony.PatchAll(typeof(AIFix)); } } } namespace StarlancerAIFix.Patches { public class AIFix { internal class ThreatComponent : MonoBehaviour, IVisibleThreat { public EnemyAI thisEnemy; public Transform eye; public float visibility; public int threatLevel; public int interestLevel; public Transform enemyTransform; public NavMeshAgent agent; public ThreatType Generic = (ThreatType)7; ThreatType IVisibleThreat.type => Generic; int IVisibleThreat.SendSpecialBehaviour(int id) { return 0; } int IVisibleThreat.GetThreatLevel(Vector3 seenByPosition) { return threatLevel; } int IVisibleThreat.GetInterestLevel() { return interestLevel; } Transform IVisibleThreat.GetThreatLookTransform() { return eye; } Transform IVisibleThreat.GetThreatTransform() { return enemyTransform; } Vector3 IVisibleThreat.GetThreatVelocity() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) if (((NetworkBehaviour)thisEnemy).IsOwner) { return agent.velocity; } return Vector3.zero; } float IVisibleThreat.GetVisibility() { if (thisEnemy.isEnemyDead) { return 0f; } visibility = 1f; return visibility; } GrabbableObject IVisibleThreat.GetHeldObject() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (thisEnemy is HoarderBugAI) { if (((HoarderBugAI)thisEnemy).heldItem == null) { return null; } return ((HoarderBugAI)thisEnemy).heldItem.itemGrabbableObject; } return null; } bool IVisibleThreat.IsThreatDead() { return thisEnemy.isEnemyDead; } } public static GameObject[] outsideAINodes; public static GameObject[] insideAINodes; public static Vector3[] outsideNodePositions; public static Vector3[] insideNodePositions; public static string[] enemyWhitelist = new string[8] { "Blob", "Butler", "Centipede", "Crawler", "Flowerman", "HoarderBug", "Nutcracker", "SandSpider" }; public static string[] hiveMoons = new string[2] { "Asteroid14Scene", "CollateralScene" }; private static GameObject[] FindOutsideAINodes() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (outsideAINodes == null || outsideAINodes.Length == 0 || (Object)(object)outsideAINodes[0] == (Object)null) { outsideAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode"); StarlancerAIFixBase.logger.LogInfo((object)"Finding outside AI nodes."); outsideNodePositions = (Vector3[])(object)new Vector3[outsideAINodes.Length]; for (int i = 0; i < outsideAINodes.Length; i++) { outsideNodePositions[i] = outsideAINodes[i].transform.position; } } return outsideAINodes; } private static GameObject[] FindInsideAINodes() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (insideAINodes == null || insideAINodes.Length == 0 || (Object)(object)insideAINodes[0] == (Object)null) { insideAINodes = GameObject.FindGameObjectsWithTag("AINode"); StarlancerAIFixBase.logger.LogInfo((object)"Finding inside AI nodes."); insideNodePositions = (Vector3[])(object)new Vector3[insideAINodes.Length]; for (int i = 0; i < insideAINodes.Length; i++) { insideNodePositions[i] = insideAINodes[i].transform.position; } } return insideAINodes; } [HarmonyPatch(typeof(EnemyAI), "Start")] [HarmonyPostfix] private static void AIFixPatch(EnemyAI __instance) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0047: 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_005a: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0117: 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) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) FindOutsideAINodes(); FindInsideAINodes(); __instance.removedPowerLevel = true; if (StartOfRound.Instance.currentLevelID == 3) { __instance.SetEnemyOutside(true); return; } Vector3 position = ((Component)__instance).transform.position; Vector3 val = Vector3.positiveInfinity; Vector3 val2 = Vector3.positiveInfinity; Vector3 val3; for (int i = 0; i < outsideNodePositions.Length; i++) { val3 = outsideNodePositions[i] - position; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; val3 = val - position; if (sqrMagnitude < ((Vector3)(ref val3)).sqrMagnitude) { val = outsideNodePositions[i]; } } for (int j = 0; j < insideAINodes.Length; j++) { val3 = insideNodePositions[j] - position; float sqrMagnitude2 = ((Vector3)(ref val3)).sqrMagnitude; val3 = val2 - position; if (sqrMagnitude2 < ((Vector3)(ref val3)).sqrMagnitude) { val2 = insideNodePositions[j]; } } if (!__instance.isOutside) { val3 = val - position; float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude; val3 = val2 - position; if (sqrMagnitude3 < ((Vector3)(ref val3)).sqrMagnitude) { __instance.SetEnemyOutside(true); int num = Random.Range(0, __instance.allAINodes.Length - 1); __instance.favoriteSpot = __instance.allAINodes[num].transform; StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance).gameObject).name} spawned outside; Switching to exterior AI. Setting Favorite Spot to {__instance.favoriteSpot}."); return; } } if (__instance.isOutside) { val3 = val - position; float sqrMagnitude4 = ((Vector3)(ref val3)).sqrMagnitude; val3 = val2 - position; if (sqrMagnitude4 > ((Vector3)(ref val3)).sqrMagnitude) { __instance.SetEnemyOutside(false); int num2 = Random.Range(0, __instance.allAINodes.Length - 1); __instance.favoriteSpot = __instance.allAINodes[num2].transform; StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance).gameObject).name} spawned inside; Switching to interior AI. Setting Favorite Spot to {__instance.favoriteSpot}."); } } } [HarmonyPatch(typeof(EnemyAI), "SubtractFromPowerLevel")] [HarmonyPostfix] private static void SubtractPowerLevelPatch(EnemyAI __instance) { EnemyAI __instance2 = __instance; if (RoundManager.Instance.currentLevel.OutsideEnemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType)) { StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the exterior enemy list has died; \nPrevious exterior power level is {RoundManager.Instance.currentOutsideEnemyPower}"); RoundManager.Instance.currentOutsideEnemyPower = Mathf.Max(RoundManager.Instance.currentOutsideEnemyPower - __instance2.enemyType.PowerLevel, 0f); StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent exterior power level is {RoundManager.Instance.currentOutsideEnemyPower}"); } else if (RoundManager.Instance.currentLevel.Enemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType)) { StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the interior enemy list has died; \nPrevious interior power level is {RoundManager.Instance.currentEnemyPower}"); RoundManager.Instance.currentEnemyPower = Mathf.Max(RoundManager.Instance.currentEnemyPower - __instance2.enemyType.PowerLevel, 0f); RoundManager.Instance.cannotSpawnMoreInsideEnemies = false; StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent interior power level is {RoundManager.Instance.currentEnemyPower}"); } else if (RoundManager.Instance.currentLevel.DaytimeEnemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType)) { StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the daytime enemy list has died; \nPrevious daytime power level is {RoundManager.Instance.currentDaytimeEnemyPower}"); RoundManager.Instance.currentDaytimeEnemyPower = Mathf.Max(RoundManager.Instance.currentDaytimeEnemyPower - __instance2.enemyType.PowerLevel, 0f); StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent daytime power level is {RoundManager.Instance.currentDaytimeEnemyPower}"); } } [HarmonyPatch(typeof(JesterAI), "Update")] [HarmonyPostfix] private static void JesterAIPatch(JesterAI __instance, ref bool ___targetingPlayer, ref float ___noPlayersToChaseTimer, ref int ___previousState) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) switch (((EnemyAI)__instance).currentBehaviourStateIndex) { case 0: if (((EnemyAI)__instance).isOutside && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null && !__instance.roamMap.inProgress) { ((EnemyAI)__instance).StartSearch(((Component)__instance).transform.position, __instance.roamMap); ((EnemyAI)__instance).SwitchToBehaviourState(0); } break; case 2: { if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && __instance.targetingPlayer && ((!((EnemyAI)__instance).isOutside && !((EnemyAI)__instance).targetPlayer.isInsideFactory) || (((EnemyAI)__instance).isOutside && ((EnemyAI)__instance).targetPlayer.isInsideFactory))) { ((EnemyAI)__instance).targetPlayer = null; } if (!((EnemyAI)__instance).isOutside) { break; } if (___previousState != 2) { ___previousState = 2; __instance.farAudio.Stop(); ((EnemyAI)__instance).creatureAnimator.SetBool("poppedOut", true); ((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier", 1f); ((EnemyAI)__instance).creatureSFX.PlayOneShot(__instance.popUpSFX); WalkieTalkie.TransmitOneShotAudio(((EnemyAI)__instance).creatureSFX, __instance.popUpSFX, 1f); ((EnemyAI)__instance).creatureVoice.clip = __instance.screamingSFX; ((EnemyAI)__instance).creatureVoice.Play(); ((EnemyAI)__instance).agent.speed = 0f; __instance.mainCollider.isTrigger = true; ((EnemyAI)__instance).agent.stoppingDistance = 0f; } ___targetingPlayer = false; for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++) { if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && !StartOfRound.Instance.allPlayerScripts[i].isInsideFactory) { ___targetingPlayer = true; break; } } if (!___targetingPlayer) { ___noPlayersToChaseTimer -= Time.deltaTime; if (___noPlayersToChaseTimer <= 0f) { ((EnemyAI)__instance).SwitchToBehaviourState(0); } } else { ___noPlayersToChaseTimer = 5f; } break; } } } [HarmonyPatch(typeof(SandWormAI), "StartEmergeAnimation")] [HarmonyPostfix] private static void SandwormResetPatch(SandWormAI __instance) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (!((EnemyAI)__instance).isOutside) { int num = Random.Range(0, ((EnemyAI)__instance).allAINodes.Length - 1); __instance.endOfFlightPathPosition = ((EnemyAI)__instance).allAINodes[num].transform.position; } } [HarmonyPatch(typeof(SandWormAI), "StartEmergeAnimation")] [HarmonyPostfix] private static void SandwormAttackPatch(SandWormAI __instance) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!((EnemyAI)__instance).isOutside) { __instance.EmergeServerRpc((int)RoundManager.Instance.YRotationThatFacesTheFarthestFromPosition(((Component)__instance).transform.position + Vector3.up * 1.5f, 30f, 6)); } } [HarmonyPatch(typeof(SpringManAI), "DoAIInterval")] [HarmonyPostfix] private static void SpringManAnimPatch(SpringManAI __instance) { if (((EnemyAI)__instance).currentBehaviourStateIndex == 0 && ((EnemyAI)__instance).isOutside && __instance.searchForPlayers.inProgress && ((EnemyAI)__instance).agent.speed >= 1f) { ((EnemyAI)__instance).creatureAnimator.SetFloat("walkSpeed", 1f); } } [HarmonyPatch(typeof(PufferAI), "Start")] [HarmonyPostfix] private static void PufferPrefabPatch(PufferAI __instance) { if (((EnemyAI)__instance).isOutside) { ((EnemyAI)__instance).currentBehaviourStateIndex = 1; } } [HarmonyPatch(typeof(ButlerEnemyAI), "Update")] [HarmonyPostfix] private static void ButlerMusicOutside(ButlerEnemyAI __instance) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) int currentBehaviourStateIndex = ((EnemyAI)__instance).currentBehaviourStateIndex; int num = currentBehaviourStateIndex; if (num == 2) { if (((EnemyAI)__instance).isOutside && !__instance.startedMurderMusic) { if (!GameNetworkManager.Instance.localPlayerController.isInsideFactory && GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 0.7f, 100f, 18, 1f, -1)) { __instance.startedMurderMusic = true; } } else { __instance.ambience1.volume = Mathf.Lerp(__instance.ambience1.volume, 0f, Time.deltaTime * 7f); if (((EnemyAI)__instance).isOutside && !GameNetworkManager.Instance.localPlayerController.isInsideFactory) { if (GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 0.7f, 100f, 18, 1f, -1)) { ButlerEnemyAI.murderMusicVolume = Mathf.Max(ButlerEnemyAI.murderMusicVolume, Mathf.Lerp(ButlerEnemyAI.murderMusicVolume, 0.7f, Time.deltaTime * 3f)); } else { ButlerEnemyAI.murderMusicVolume = Mathf.Max(ButlerEnemyAI.murderMusicVolume, Mathf.Lerp(ButlerEnemyAI.murderMusicVolume, 0.36f, Time.deltaTime * 3f)); } ButlerEnemyAI.increaseMurderMusicVolume = true; } if (__instance.ambience1.isPlaying && __instance.ambience1.volume <= 0.01f) { __instance.ambience1.Stop(); } if (!ButlerEnemyAI.murderMusicAudio.isPlaying) { ButlerEnemyAI.murderMusicAudio.Play(); } } } if ((((EnemyAI)__instance).isEnemyDead || StartOfRound.Instance.shipIsLeaving) && __instance.startedMurderMusic) { __instance.startedMurderMusic = false; } } [HarmonyPatch(typeof(RedLocustBees), "Start")] [HarmonyPostfix] private static void DoNotGrabHive(RedLocustBees __instance) { if (!hiveMoons.Contains(RoundManager.Instance.currentLevel.sceneName) && !StarlancerAIFixBase.configLootBugHives.Value) { Debug.LogWarning((object)"Making this hive ungrabbable by enemies"); __instance.hive.grabbableToEnemies = false; } } [HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")] [HarmonyPrefix] private static bool EnemyMeshPatch(EnemyAI __instance, bool enable, bool overrideDoNotSet = false) { int num = 0; int num2 = 0; int layer = ((!enable) ? 23 : 19); for (int i = 0; i < __instance.skinnedMeshRenderers.Length; i++) { if ((Object)(object)__instance.skinnedMeshRenderers[i] != (Object)null && (!((Component)__instance.skinnedMeshRenderers[i]).CompareTag("DoNotSet") || overrideDoNotSet)) { ((Component)__instance.skinnedMeshRenderers[i]).gameObject.layer = layer; } else { if (!((Object)(object)__instance.skinnedMeshRenderers[i] == (Object)null)) { continue; } List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(__instance.skinnedMeshRenderers); int num3 = 0; while (num3 < list.Count) { if ((Object)(object)list[num3] == (Object)null) { num++; list.RemoveAt(num3); } else { num3++; } } StarlancerAIFixBase.logger.LogWarning((object)$"Found and removed {num} null SkinnedMeshRenderers in {((Object)((Component)__instance).gameObject).name} ({__instance.thisEnemyIndex}) to prevent potential null reference exceptions."); __instance.skinnedMeshRenderers = list.ToArray(); } } for (int j = 0; j < __instance.meshRenderers.Length; j++) { if ((Object)(object)__instance.meshRenderers[j] != (Object)null && (!((Component)__instance.meshRenderers[j]).CompareTag("DoNotSet") || overrideDoNotSet)) { ((Component)__instance.meshRenderers[j]).gameObject.layer = layer; } else { if (!((Object)(object)__instance.meshRenderers[j] == (Object)null)) { continue; } List<MeshRenderer> list2 = new List<MeshRenderer>(__instance.meshRenderers); int num4 = 0; while (num4 < list2.Count) { if ((Object)(object)list2[num4] == (Object)null) { num2++; list2.RemoveAt(num4); } else { num4++; } } StarlancerAIFixBase.logger.LogWarning((object)$"Found and removed {num2} null MeshRenderers in {((Object)((Component)__instance).gameObject).name} ({__instance.thisEnemyIndex}) to prevent potential null reference exceptions."); __instance.meshRenderers = list2.ToArray(); } } return false; } [HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")] [HarmonyPrefix] private static void PlayerIsTargetablePatch(ref bool overrideInsideFactoryCheck) { if (StartOfRound.Instance.currentLevelID == 3) { overrideInsideFactoryCheck = true; } } [HarmonyPatch(typeof(EnemyAI), "Start")] [HarmonyPostfix] private static void DummyCollider(EnemyAI __instance) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) BoxCollider component = ((Component)__instance).gameObject.GetComponent<BoxCollider>(); if ((Object)(object)component == (Object)null) { component = ((Component)__instance).gameObject.AddComponent<BoxCollider>(); ((Collider)component).isTrigger = true; ((Collider)component).enabled = true; component.size = Vector3.zero; } } [HarmonyPatch(typeof(EnemyAI), "Start")] [HarmonyPostfix] private static void ThreatPatch(EnemyAI __instance) { if (Array.IndexOf(enemyWhitelist, ((Object)__instance.enemyType).name) != -1) { StarlancerAIFixBase.logger.LogInfo((object)("The Enemy Whitelist contains: " + string.Join(", ", enemyWhitelist) + ".")); IVisibleThreat componentInChildren = ((Component)__instance).GetComponentInChildren<IVisibleThreat>(); if (componentInChildren == null && componentInChildren == null) { StarlancerAIFixBase.logger.LogInfo((object)("Adding IVisibleThreat component to " + ((Object)((Component)__instance).gameObject).name + ".")); ThreatComponent threatComponent = ((Component)__instance).gameObject.AddComponent<ThreatComponent>(); threatComponent.thisEnemy = __instance; threatComponent.eye = __instance.eye; threatComponent.visibility = 0.5f; threatComponent.threatLevel = 3; threatComponent.interestLevel = 0; threatComponent.enemyTransform = ((Component)__instance).transform; threatComponent.agent = __instance.agent; } } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }