using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StarlancerAIFix.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[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+1bb27691dbd3412ca60ea3e3c147ba0391858db5")]
[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
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("AudioKnight.StarlancerAIFix", "Starlancer AI Fix", "3.6.0")]
public class StarlancerAIFixBase : BaseUnityPlugin
{
private const string modGUID = "AudioKnight.StarlancerAIFix";
private const string modName = "Starlancer AI Fix";
private const string modVersion = "3.6.0";
private readonly Harmony harmony = new Harmony("AudioKnight.StarlancerAIFix");
public static StarlancerAIFixBase Instance;
internal static ManualLogSource logger;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"Starlancer AI Fix Online.");
harmony.PatchAll(typeof(StarlancerAIFixBase));
harmony.PatchAll(typeof(AIFix));
foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
{
BepInPlugin metadata = pluginInfo.Value.Metadata;
if (metadata.GUID.Equals("xCeezy.LethalEscape"))
{
logger.LogInfo((object)"LethalEscape is active, disabling LEsc's JesterAI.Update() Postfix to ensure compatibility with SLAI.");
harmony.Unpatch((MethodBase)typeof(JesterAI).GetMethod("Update"), (HarmonyPatchType)2, "LethalEscape");
break;
}
}
}
}
}
namespace StarlancerAIFix.Patches
{
public class AIFix
{
public static GameObject[] outsideAINodes;
public static GameObject[] insideAINodes;
public static Vector3[] outsideNodePositions;
public static Vector3[] insideNodePositions;
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_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//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_0030: 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)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
FindOutsideAINodes();
FindInsideAINodes();
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(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 (!((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(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(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;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}