using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; 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+fe10d54082762d1e49bcb6a387ddf16d7c436f54")] [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.13.1")] public class StarlancerAIFixBase : BaseUnityPlugin { private const string modGUID = "AudioKnight.StarlancerAIFix"; private const string modName = "Starlancer AI Fix"; private const string modVersion = "3.13.1"; 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 configLootBugHives; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } configLootBugHives = ((BaseUnityPlugin)this).Config.Bind("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 List outsideSpawnedEnemies = new List(); private static List insideSpawnedEnemies = new List(); private static List daytimeSpawnedEnemies = new List(); private static List weedSpawnedEnemies = new List(); 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.LogDebug((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.LogDebug((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); } else { 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.LogDebug((object)$"{((Object)((Component)__instance).gameObject).name} spawned outside; Switching to exterior AI. Setting Favorite Spot to {__instance.favoriteSpot}."); goto IL_0225; } } 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.LogDebug((object)$"{((Object)((Component)__instance).gameObject).name} spawned inside; Switching to interior AI. Setting Favorite Spot to {__instance.favoriteSpot}."); } } } goto IL_0225; IL_0225: if (__instance.isOutside) { if (__instance.enemyType.spawnFromWeeds) { weedSpawnedEnemies.Add(__instance); } else if (__instance.enemyType.isDaytimeEnemy) { daytimeSpawnedEnemies.Add(__instance); } else { outsideSpawnedEnemies.Add(__instance); } } else { insideSpawnedEnemies.Add(__instance); } } [HarmonyPatch(typeof(EnemyAI), "SubtractFromPowerLevel")] [HarmonyPostfix] private static void SubtractPowerLevelPatch(EnemyAI __instance) { if (outsideSpawnedEnemies.Contains(__instance)) { StarlancerAIFixBase.logger.LogDebug((object)$"{((Object)((Component)__instance).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 - __instance.enemyType.PowerLevel, 0f); outsideSpawnedEnemies.Remove(__instance); StarlancerAIFixBase.logger.LogDebug((object)$"Removing {((Object)((Component)__instance).gameObject).name}'s power ({__instance.enemyType.PowerLevel}) from the RoundManager; \nCurrent exterior power level is {RoundManager.Instance.currentOutsideEnemyPower}"); } else if (insideSpawnedEnemies.Contains(__instance)) { StarlancerAIFixBase.logger.LogDebug((object)$"{((Object)((Component)__instance).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 - __instance.enemyType.PowerLevel, 0f); RoundManager.Instance.cannotSpawnMoreInsideEnemies = false; insideSpawnedEnemies.Remove(__instance); StarlancerAIFixBase.logger.LogDebug((object)$"Removing {((Object)((Component)__instance).gameObject).name}'s power ({__instance.enemyType.PowerLevel}) from the RoundManager; \nCurrent interior power level is {RoundManager.Instance.currentEnemyPower}"); } else if (daytimeSpawnedEnemies.Contains(__instance)) { StarlancerAIFixBase.logger.LogDebug((object)$"{((Object)((Component)__instance).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 - __instance.enemyType.PowerLevel, 0f); daytimeSpawnedEnemies.Remove(__instance); StarlancerAIFixBase.logger.LogDebug((object)$"Removing {((Object)((Component)__instance).gameObject).name}'s power ({__instance.enemyType.PowerLevel}) from the RoundManager; \nCurrent daytime power level is {RoundManager.Instance.currentDaytimeEnemyPower}"); } else if (weedSpawnedEnemies.Contains(__instance)) { StarlancerAIFixBase.logger.LogDebug((object)$"{((Object)((Component)__instance).gameObject).name} from the weed enemy list has died; \nPrevious weed power level is {RoundManager.Instance.currentWeedEnemyPower}"); RoundManager.Instance.currentWeedEnemyPower = Mathf.Max(RoundManager.Instance.currentWeedEnemyPower - __instance.enemyType.PowerLevel, 0f); weedSpawnedEnemies.Remove(__instance); StarlancerAIFixBase.logger.LogDebug((object)$"Removing {((Object)((Component)__instance).gameObject).name}'s power ({__instance.enemyType.PowerLevel}) from the RoundManager; \nCurrent weed 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) { StarlancerAIFixBase.logger.LogDebug((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, bool tamperWithMeshes = 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 list = new List(__instance.skinnedMeshRenderers); int num3 = 0; while (num3 < list.Count) { if ((Object)(object)list[num3] == (Object)null) { num++; list.RemoveAt(num3); } else { num3++; } } __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 list2 = new List(__instance.meshRenderers); int num4 = 0; while (num4 < list2.Count) { if ((Object)(object)list2[num4] == (Object)null) { num2++; list2.RemoveAt(num4); } else { num4++; } } __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(StingrayAI), "MakePlayerSlipOnSlime")] [HarmonyTranspiler] private static IEnumerable SlipOnSlimeOutsideTranspiler(IEnumerable instructions) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown FieldInfo field = typeof(PlayerControllerB).GetField("isInsideFactory", BindingFlags.Instance | BindingFlags.Public); CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)field, (string)null), new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null) }); if (val.IsValid) { val.RemoveInstructions(3); return val.InstructionEnumeration(); } return instructions; } [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(); if ((Object)(object)component == (Object)null) { component = ((Component)__instance).gameObject.AddComponent(); ((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.LogDebug((object)("The Enemy Whitelist contains: " + string.Join(", ", enemyWhitelist) + ".")); IVisibleThreat componentInChildren = ((Component)__instance).GetComponentInChildren(); if (componentInChildren == null && componentInChildren == null) { StarlancerAIFixBase.logger.LogDebug((object)("Adding IVisibleThreat component to " + ((Object)((Component)__instance).gameObject).name + ".")); ThreatComponent threatComponent = ((Component)__instance).gameObject.AddComponent(); 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) { } } }