Decompiled source of FairAI Quicksand Fix v1.5.5
FairAI.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading.Tasks; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using FairAI; using FairAI.Component; using FairAI.Patches; using GameNetcodeStuff; using HarmonyLib; using LethalConfig; using LethalConfig.ConfigItems; using LethalThings; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: AssemblyCompany("FairAI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4d5a6d1dff023682b2e316ab57406ea33e3e92a2")] [assembly: AssemblyProduct("FairAI")] [assembly: AssemblyTitle("FairAI")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } internal class TurretAIPatch { public static float viewRadius = 16f; public static float viewAngle = 90f; public static bool PatchUpdate(ref Turret __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Expected I4, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null) && Plugin.AllowFairness(((Component)__instance).transform.position)) { FAIR_AI fAIR_AI = ((Component)__instance).gameObject.GetComponent<FAIR_AI>() ?? ((Component)__instance).gameObject.AddComponent<FAIR_AI>(); Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("wasTargetingPlayerLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic); typeFromHandle.GetMethod("SetTargetToPlayerBody", BindingFlags.Instance | BindingFlags.NonPublic); typeFromHandle.GetMethod("TurnTowardsTargetIfHasLOS", BindingFlags.Instance | BindingFlags.NonPublic); if (!__instance.turretActive) { field.SetValue(__instance, false); __instance.turretMode = (TurretMode)0; __instance.targetPlayerWithRotation = null; fAIR_AI.targetWithRotation = null; return false; } if ((Object)(object)fAIR_AI.targetWithRotation != (Object)null || (Object)(object)__instance.targetPlayerWithRotation != (Object)null) { if (!(bool)field.GetValue(__instance)) { field.SetValue(__instance, true); if ((int)__instance.turretMode == 0) { if ((Object)(object)fAIR_AI.targetWithRotation != (Object)null) { __instance.turretMode = (TurretMode)2; } else { __instance.turretMode = (TurretMode)1; } } } SetTargetToEnemyBody(ref __instance); TurnTowardsTargetEnemyIfHasLOS(ref __instance); } else if ((bool)field.GetValue(__instance)) { field.SetValue(__instance, false); __instance.turretMode = (TurretMode)0; } TurretMode turretMode = __instance.turretMode; switch ((int)turretMode) { case 0: DetectionFunction(__instance, fAIR_AI); break; case 1: ChargingFunction(__instance, fAIR_AI); break; case 2: FiringFunction(__instance); break; case 3: BerserkFunction(__instance); break; } if ((bool)field2.GetValue(__instance)) { __instance.turnTowardsObjectCompass.localEulerAngles = new Vector3(-180f, __instance.turretRod.localEulerAngles.y - Time.deltaTime * 20f, 180f); __instance.turretRod.rotation = Quaternion.RotateTowards(__instance.turretRod.rotation, __instance.turnTowardsObjectCompass.rotation, __instance.rotationSpeed * Time.deltaTime); return false; } if ((bool)field3.GetValue(__instance)) { __instance.turnTowardsObjectCompass.localEulerAngles = new Vector3(-180f, Mathf.Clamp(__instance.targetRotation, 0f - __instance.rotationRange, __instance.rotationRange), 180f); } __instance.turretRod.rotation = Quaternion.RotateTowards(__instance.turretRod.rotation, __instance.turnTowardsObjectCompass.rotation, __instance.rotationSpeed * Time.deltaTime); return false; } return false; } public static void DetectionFunction(Turret turret, FAIR_AI turret_ai) { //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_02fd: Unknown result type (might be due to invalid IL or missing references) Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field4 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field5 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field6 = typeFromHandle.GetField("switchRotationTimer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field7 = typeFromHandle.GetField("rotatingRight", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method2 = typeFromHandle.GetMethod("FadeBulletAudio", BindingFlags.Instance | BindingFlags.NonPublic); if ((int)field.GetValue(turret) != 0) { field.SetValue(turret, (object)(TurretMode)0); field2.SetValue(turret, false); turret.mainAudio.Stop(); turret.farAudio.Stop(); turret.berserkAudio.Stop(); if (field3.GetValue(turret) != null) { ((MonoBehaviour)turret).StopCoroutine((Coroutine)field3.GetValue(turret)); } field3.SetValue(turret, ((MonoBehaviour)turret).StartCoroutine((IEnumerator)method2.Invoke(turret, new object[0]))); turret.bulletParticles.Stop(true, (ParticleSystemStopBehavior)1); if (Plugin.turretSettings.Count > 7) { turret.rotationSpeed = Plugin.turretSettings[5]; } else { turret.rotationSpeed = 28f; } field4.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); field5.SetValue(turret, Random.Range(0f, 0.15f)); } if (!((NetworkBehaviour)turret).IsServer) { return; } if (Plugin.turretSettings.Count > 7) { if ((float)field6.GetValue(turret) >= Plugin.turretSettings[3]) { field6.SetValue(turret, 0f); bool flag = !(bool)field7.GetValue(turret); turret.SwitchRotationClientRpc(flag); turret.SwitchRotationOnInterval(flag); } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } } else if ((float)field6.GetValue(turret) >= 7f) { field6.SetValue(turret, 0f); bool flag2 = !(bool)field7.GetValue(turret); turret.SwitchRotationClientRpc(flag2); turret.SwitchRotationOnInterval(flag2); } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } if ((float)field5.GetValue(turret) >= 0.25f) { field5.SetValue(turret, 0f); EnemyAICollisionDetect val = CheckForEnemiesInLineOfSight(turret, 15f); if ((Object)(object)val != (Object)null && !val.mainScript.isEnemyDead && Plugin.CanMob("TurretTargetAllMobs", ".Turret Target", val.mainScript.enemyType.enemyName)) { turret_ai.targetWithRotation = val.mainScript; turret.turretMode = (TurretMode)2; turret.SetToModeClientRpc(2); method.Invoke(turret, new object[1] { (object)(TurretMode)2 }); turret_ai.SwitchedTargetedEnemyClientRpc(turret, val.mainScript); Plugin.logger.LogInfo((object)"Detected Enemy!"); return; } field5.SetValue(turret, 0f); PlayerControllerB val2 = CheckForPlayersInLOS(turret, 1.35f, angleRangeCheck: true); if ((Object)(object)val2 != (Object)null && !val2.isPlayerDead) { turret.targetPlayerWithRotation = val2; method.Invoke(turret, new object[1] { 1 }); turret.SwitchTargetedPlayerClientRpc((int)val2.playerClientId, true); Plugin.logger.LogInfo((object)"Detected Player!"); } } else { field5.SetValue(turret, (float)field5.GetValue(turret) + Time.deltaTime); } } public static void ChargingFunction(Turret turret, FAIR_AI turret_ai) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Invalid comparison between Unknown and I4 Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("hasLineOfSight", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field4 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field5 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field6 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic); if ((int)(TurretMode)field2.GetValue(turret) != 1) { field2.SetValue(turret, (object)(TurretMode)1); field3.SetValue(turret, false); turret.mainAudio.PlayOneShot(turret.detectPlayerSFX); turret.berserkAudio.Stop(); WalkieTalkie.TransmitOneShotAudio(turret.mainAudio, turret.detectPlayerSFX, 1f); if (Plugin.turretSettings.Count > 7) { turret.rotationSpeed = Plugin.turretSettings[6]; } else { turret.rotationSpeed = 95f; } field4.SetValue(turret, false); field6.SetValue(turret, 0f); turret.turretAnimator.SetInteger("TurretMode", 1); } if (!((NetworkBehaviour)turret).IsServer) { return; } if ((float)field5.GetValue(turret) >= 1.5f) { field5.SetValue(turret, 0f); Plugin.logger.LogInfo((object)"Charging timer is up, setting to firing mode"); if (!(bool)field.GetValue(turret)) { Plugin.logger.LogInfo((object)"hasLineOfSight is false"); turret.targetPlayerWithRotation = null; turret.RemoveTargetedPlayerClientRpc(); turret_ai.targetWithRotation = null; turret_ai.RemoveTargetedEnemyClientRpc(); } else { method.Invoke(turret, new object[1] { 2 }); turret.SetToModeClientRpc(2); } } else { field5.SetValue(turret, (float)field5.GetValue(turret) + Time.deltaTime); } } public static void FiringFunction(Turret turret) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Invalid comparison between Unknown and I4 //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_0713: Unknown result type (might be due to invalid IL or missing references) //IL_071e: Unknown result type (might be due to invalid IL or missing references) //IL_0723: Unknown result type (might be due to invalid IL or missing references) //IL_0734: Unknown result type (might be due to invalid IL or missing references) //IL_0742: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_07bb: Unknown result type (might be due to invalid IL or missing references) //IL_07c0: Unknown result type (might be due to invalid IL or missing references) //IL_07e0: Unknown result type (might be due to invalid IL or missing references) //IL_07e5: Unknown result type (might be due to invalid IL or missing references) //IL_07e7: Unknown result type (might be due to invalid IL or missing references) //IL_07ec: Unknown result type (might be due to invalid IL or missing references) //IL_07fa: Unknown result type (might be due to invalid IL or missing references) //IL_07ff: Unknown result type (might be due to invalid IL or missing references) //IL_0763: Unknown result type (might be due to invalid IL or missing references) //IL_0782: Unknown result type (might be due to invalid IL or missing references) //IL_078f: Unknown result type (might be due to invalid IL or missing references) //IL_0794: Unknown result type (might be due to invalid IL or missing references) //IL_0796: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Unknown result type (might be due to invalid IL or missing references) //IL_079a: Unknown result type (might be due to invalid IL or missing references) //IL_07ab: Unknown result type (might be due to invalid IL or missing references) //IL_0685: Unknown result type (might be due to invalid IL or missing references) //IL_068b: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_06e9: Unknown result type (might be due to invalid IL or missing references) //IL_06f3: Unknown result type (might be due to invalid IL or missing references) //IL_06fd: Unknown result type (might be due to invalid IL or missing references) //IL_0703: Unknown result type (might be due to invalid IL or missing references) //IL_06ca: Unknown result type (might be due to invalid IL or missing references) //IL_06d0: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_08ae: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_0939: Unknown result type (might be due to invalid IL or missing references) //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_09b7: Unknown result type (might be due to invalid IL or missing references) //IL_0583: Unknown result type (might be due to invalid IL or missing references) Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("wasTargetingPlayerLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("targetingDeadPlayer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field4 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field5 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field6 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field7 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field8 = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field9 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic); if ((int)(TurretMode)field2.GetValue(turret) != 2) { field2.SetValue(turret, (object)(TurretMode)2); turret.berserkAudio.Stop(); RoundManager.Instance.PlayAudibleNoise(((Component)turret.berserkAudio).transform.position, 15f, 0.9f, 0, false, 0); turret.mainAudio.clip = turret.firingSFX; turret.mainAudio.Play(); turret.farAudio.clip = turret.firingFarSFX; turret.farAudio.Play(); turret.bulletParticles.Play(true); turret.bulletCollisionAudio.Play(); if (field4 != null && field4.GetValue(turret) != null) { ((MonoBehaviour)turret).StopCoroutine((Coroutine)field4.GetValue(turret)); } turret.bulletCollisionAudio.volume = 1f; field5.SetValue(turret, false); field7.SetValue(turret, 0f); turret.turretAnimator.SetInteger("TurretMode", 2); } Ray val5; if (Plugin.turretSettings.Count > 7) { if ((float)field6.GetValue(turret) >= Plugin.turretSettings[1]) { Plugin.logger.LogInfo((object)"Attacking Target"); field6.SetValue(turret, 0f); if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController) { int num = (int)Plugin.turretSettings[0]; if (num <= 0) { GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); GameNetworkManager.Instance.localPlayerController.DamagePlayer(num, false, true, (CauseOfDeath)0, 0, false, default(Vector3)); GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); } else if ((float)GameNetworkManager.Instance.localPlayerController.health > Plugin.turretSettings[0]) { GameNetworkManager.Instance.localPlayerController.DamagePlayer(num, true, true, (CauseOfDeath)7, 0, false, default(Vector3)); } else { GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3)); } } field8.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward)); RaycastHit val = default(RaycastHit); if (Physics.Raycast((Ray)field8.GetValue(turret), ref val, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1)) { field9.SetValue(turret, val); Transform transform = ((Component)turret.bulletCollisionAudio).transform; Ray val2 = (Ray)field8.GetValue(turret); RaycastHit val3 = (RaycastHit)field9.GetValue(turret); Ray val4 = val2; val5 = val4; transform.position = ((Ray)(ref val5)).GetPoint(((RaycastHit)(ref val3)).distance - 0.5f); } Vector3 forward = turret.aimPoint.forward; forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward; Plugin.AttackTargets(((Component)turret).GetComponent<FAIR_AI>(), turret.aimPoint.position, forward, 30f); FAIR_AI component = ((Component)turret).GetComponent<FAIR_AI>(); if ((Object)(object)component.targetWithRotation != (Object)null) { EnemyAICollisionDetect component2 = ((Component)component.targetWithRotation).GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component2 != (Object)null && (component2.mainScript.isEnemyDead || component2.mainScript.enemyHP <= 0)) { component.targetWithRotation = null; component.RemoveTargetedEnemyClientRpc(); } } if ((Object)(object)turret.targetPlayerWithRotation != (Object)null && turret.targetPlayerWithRotation.isPlayerDead) { turret.targetPlayerWithRotation = null; turret.RemoveTargetedPlayerClientRpc(); } if ((Object)(object)turret.targetPlayerWithRotation == (Object)null && (Object)(object)component.targetWithRotation == (Object)null) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } else { if (!((Object)(object)turret.targetTransform != (Object)null)) { return; } if ((Object)(object)((Component)turret.targetTransform).GetComponent<EnemyAI>() != (Object)null) { if (((Component)turret.targetTransform).GetComponent<EnemyAI>().isEnemyDead) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } } else if (Object.op_Implicit((Object)(object)((Component)turret.targetTransform).GetComponent<EnemyAICollisionDetect>()) && ((Component)turret.targetTransform).GetComponent<EnemyAICollisionDetect>().mainScript.isEnemyDead) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } } } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } } else if ((float)field6.GetValue(turret) >= 0.21f) { Plugin.logger.LogInfo((object)"Attacking Target"); field6.SetValue(turret, 0f); if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController) { int @int = Plugin.GetInt("TurretConfig", "Player Damage"); if (@int <= 0) { GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); GameNetworkManager.Instance.localPlayerController.DamagePlayer(@int, false, true, (CauseOfDeath)0, 0, false, default(Vector3)); GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); } else if (GameNetworkManager.Instance.localPlayerController.health > 50) { GameNetworkManager.Instance.localPlayerController.DamagePlayer(@int, true, true, (CauseOfDeath)7, 0, false, default(Vector3)); } else { GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3)); } } field8.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward)); RaycastHit val6 = default(RaycastHit); if (Physics.Raycast((Ray)field8.GetValue(turret), ref val6, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1)) { field9.SetValue(turret, val6); Transform transform2 = ((Component)turret.bulletCollisionAudio).transform; Ray val7 = (Ray)field8.GetValue(turret); RaycastHit val8 = (RaycastHit)field9.GetValue(turret); Ray val9 = val7; val5 = val9; transform2.position = ((Ray)(ref val5)).GetPoint(((RaycastHit)(ref val8)).distance - 0.5f); } Vector3 forward2 = turret.aimPoint.forward; forward2 = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward2; Plugin.AttackTargets(((Component)turret).GetComponent<FAIR_AI>(), turret.aimPoint.position, forward2, 30f); FAIR_AI component3 = ((Component)turret).GetComponent<FAIR_AI>(); if ((Object)(object)component3.targetWithRotation != (Object)null) { EnemyAICollisionDetect component4 = ((Component)component3.targetWithRotation).GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component4 != (Object)null && (component4.mainScript.isEnemyDead || component4.mainScript.enemyHP <= 0)) { component3.targetWithRotation = null; component3.RemoveTargetedEnemyClientRpc(); } } if ((Object)(object)turret.targetPlayerWithRotation != (Object)null && turret.targetPlayerWithRotation.isPlayerDead) { turret.targetPlayerWithRotation = null; turret.RemoveTargetedPlayerClientRpc(); } if ((Object)(object)turret.targetPlayerWithRotation == (Object)null && (Object)(object)component3.targetWithRotation == (Object)null) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } else { if (!((Object)(object)turret.targetTransform != (Object)null)) { return; } if ((Object)(object)((Component)turret.targetTransform).GetComponent<EnemyAI>() != (Object)null) { if (((Component)turret.targetTransform).GetComponent<EnemyAI>().isEnemyDead) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } } else if (Object.op_Implicit((Object)(object)((Component)turret.targetTransform).GetComponent<EnemyAICollisionDetect>()) && ((Component)turret.targetTransform).GetComponent<EnemyAICollisionDetect>().mainScript.isEnemyDead) { turret.turretMode = (TurretMode)0; turret.SetToModeClientRpc(0); field.SetValue(turret, false); field3.SetValue(turret, true); turret.turretAnimator.SetInteger("TurretMode", 0); method.Invoke(turret, new object[1] { (object)(TurretMode)0 }); } } } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } } public static void BerserkFunction(Turret turret) { //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Invalid comparison between Unknown and I4 //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown //IL_05cb: Unknown result type (might be due to invalid IL or missing references) //IL_05d6: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Unknown result type (might be due to invalid IL or missing references) //IL_05ec: Unknown result type (might be due to invalid IL or missing references) //IL_05fa: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_0673: Unknown result type (might be due to invalid IL or missing references) //IL_0678: Unknown result type (might be due to invalid IL or missing references) //IL_0698: Unknown result type (might be due to invalid IL or missing references) //IL_069d: Unknown result type (might be due to invalid IL or missing references) //IL_069f: Unknown result type (might be due to invalid IL or missing references) //IL_06a4: Unknown result type (might be due to invalid IL or missing references) //IL_06b2: Unknown result type (might be due to invalid IL or missing references) //IL_06b7: Unknown result type (might be due to invalid IL or missing references) //IL_061b: Unknown result type (might be due to invalid IL or missing references) //IL_063a: Unknown result type (might be due to invalid IL or missing references) //IL_063f: Unknown result type (might be due to invalid IL or missing references) //IL_0649: Unknown result type (might be due to invalid IL or missing references) //IL_064e: Unknown result type (might be due to invalid IL or missing references) //IL_0650: Unknown result type (might be due to invalid IL or missing references) //IL_0652: Unknown result type (might be due to invalid IL or missing references) //IL_0663: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Unknown result type (might be due to invalid IL or missing references) //IL_0543: Unknown result type (might be due to invalid IL or missing references) //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0445: Unknown result type (might be due to invalid IL or missing references) //IL_0465: Unknown result type (might be due to invalid IL or missing references) //IL_046a: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Unknown result type (might be due to invalid IL or missing references) //IL_047f: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_0407: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_05a1: Unknown result type (might be due to invalid IL or missing references) //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Unknown result type (might be due to invalid IL or missing references) //IL_05bb: Unknown result type (might be due to invalid IL or missing references) //IL_0582: Unknown result type (might be due to invalid IL or missing references) //IL_0588: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_0382: 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_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("wasTargetingPlayerLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field4 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field5 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field6 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field7 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field8 = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field9 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field10 = typeFromHandle.GetField("berserkTimer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field11 = typeFromHandle.GetField("enteringBerserkMode", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic); if ((int)(TurretMode)field2.GetValue(turret) != 3) { field2.SetValue(turret, (object)(TurretMode)3); turret.turretAnimator.SetInteger("TurretMode", 1); field10.SetValue(turret, 1.3f); turret.berserkAudio.Play(); if (Plugin.turretSettings.Count > 7) { turret.rotationSpeed = Plugin.turretSettings[7]; } else { turret.rotationSpeed = 77f; } field11.SetValue(turret, true); field5.SetValue(turret, true); field7.SetValue(turret, 0f); field.SetValue(turret, false); turret.targetPlayerWithRotation = null; } if ((bool)field11.GetValue(turret)) { field10.SetValue(turret, (float)field10.GetValue(turret) - Time.deltaTime); if ((float)field10.GetValue(turret) <= 0f) { field11.SetValue(turret, false); field3.SetValue(turret, true); field10.SetValue(turret, 9f); turret.turretAnimator.SetInteger("TurretMode", 2); turret.mainAudio.clip = turret.firingSFX; turret.mainAudio.Play(); turret.farAudio.clip = turret.firingFarSFX; turret.farAudio.Play(); turret.bulletParticles.Play(true); turret.bulletCollisionAudio.Play(); if (field4 != null) { ((MonoBehaviour)turret).StopCoroutine((Coroutine)field4.GetValue(turret)); } turret.bulletCollisionAudio.volume = 1f; } return; } Ray val4; if (Plugin.turretSettings.Count > 7) { if ((float)field6.GetValue(turret) >= Plugin.turretSettings[1]) { field6.SetValue(turret, 0f); if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController) { int num = (int)Plugin.turretSettings[0]; if (num <= 0) { GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); GameNetworkManager.Instance.localPlayerController.DamagePlayer(num, false, true, (CauseOfDeath)0, 0, false, default(Vector3)); GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); } else if (GameNetworkManager.Instance.localPlayerController.health > num) { GameNetworkManager.Instance.localPlayerController.DamagePlayer(num, true, true, (CauseOfDeath)7, 0, false, default(Vector3)); } else { GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3)); } } field8.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward)); RaycastHit val = default(RaycastHit); if (Physics.Raycast((Ray)field8.GetValue(turret), ref val, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1)) { field9.SetValue(turret, val); Transform transform = ((Component)turret.bulletCollisionAudio).transform; Ray val2 = (Ray)field8.GetValue(turret); RaycastHit val3 = (RaycastHit)field9.GetValue(turret); val4 = val2; transform.position = ((Ray)(ref val4)).GetPoint(((RaycastHit)(ref val3)).distance - 0.5f); } Vector3 forward = turret.aimPoint.forward; forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward; Plugin.AttackTargets(((Component)turret).GetComponent<FAIR_AI>(), turret.centerPoint.position, forward, 30f); } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } } else if ((float)field6.GetValue(turret) >= 0.21f) { field6.SetValue(turret, 0f); if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController) { int @int = Plugin.GetInt("TurretConfig", "Player Damage"); if (@int <= 0) { GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); GameNetworkManager.Instance.localPlayerController.DamagePlayer(@int, false, true, (CauseOfDeath)0, 0, false, default(Vector3)); GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false); } else if (GameNetworkManager.Instance.localPlayerController.health > 50) { GameNetworkManager.Instance.localPlayerController.DamagePlayer(@int, true, true, (CauseOfDeath)7, 0, false, default(Vector3)); } else { GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3)); } } field8.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward)); RaycastHit val5 = default(RaycastHit); if (Physics.Raycast((Ray)field8.GetValue(turret), ref val5, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1)) { field9.SetValue(turret, val5); Transform transform2 = ((Component)turret.bulletCollisionAudio).transform; Ray val6 = (Ray)field8.GetValue(turret); RaycastHit val7 = (RaycastHit)field9.GetValue(turret); val4 = val6; transform2.position = ((Ray)(ref val4)).GetPoint(((RaycastHit)(ref val7)).distance - 0.5f); } Vector3 forward2 = turret.aimPoint.forward; forward2 = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward2; Plugin.AttackTargets(((Component)turret).GetComponent<FAIR_AI>(), turret.centerPoint.position, forward2, 30f); } else { field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime); } if (((NetworkBehaviour)turret).IsServer) { field10.SetValue(turret, (float)field10.GetValue(turret) - Time.deltaTime); if ((float)field10.GetValue(turret) <= 0f) { method.Invoke(turret, new object[1] { 0 }); turret.SetToModeClientRpc(0); } } } public static bool CheckForTargetsInLOS(ref Turret __instance, float radius = 2f, bool angleRangeCheck = false) { FAIR_AI component = ((Component)__instance).gameObject.GetComponent<FAIR_AI>(); PlayerControllerB val = CheckForPlayersInLOS(__instance, radius, angleRangeCheck); EnemyAICollisionDetect val2 = CheckForEnemiesInLineOfSight(__instance, radius, angleRangeCheck); if ((Object)(object)val != (Object)null) { component.targets = new Dictionary<int, GameObject> { { 0, ((Component)val).gameObject } }; return true; } if ((Object)(object)val2 != (Object)null) { component.targets = new Dictionary<int, GameObject> { { 1, ((Component)val2).gameObject } }; return true; } return false; } public static PlayerControllerB CheckForPlayersInLOS(Turret turret, float radius = 2f, bool angleRangeCheck = false) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0207: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Invalid comparison between Unknown and I4 //IL_00f3: 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_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Invalid comparison between Unknown and I4 //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) Vector3 val = turret.aimPoint.forward; val = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / radius, 0f) * val; float num = turret.rotationRange / radius * 2f; Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("enteringBerserkMode", BindingFlags.Instance | BindingFlags.NonPublic); RaycastHit val2 = default(RaycastHit); for (int i = 0; i <= 6; i++) { field.SetValue(turret, (object)new Ray(turret.centerPoint.position, val)); if (Physics.Raycast((Ray)field.GetValue(turret), ref val2, 30f, 1051400, (QueryTriggerInteraction)1)) { field2.SetValue(turret, val2); RaycastHit val3 = (RaycastHit)field2.GetValue(turret); if (((Component)((RaycastHit)(ref val3)).transform).CompareTag("Player")) { val3 = (RaycastHit)field2.GetValue(turret); PlayerControllerB component = ((Component)((RaycastHit)(ref val3)).transform).GetComponent<PlayerControllerB>(); if (!((Object)(object)component == (Object)null)) { if (angleRangeCheck && Vector3.Angle(((Component)component).transform.position + Vector3.up * 1.75f - turret.centerPoint.position, turret.forwardFacingPos.forward) > turret.rotationRange) { return null; } return component; } continue; } if ((int)turret.turretMode == 2 || ((int)turret.turretMode == 3 && !(bool)field3.GetValue(turret))) { val3 = (RaycastHit)field2.GetValue(turret); if (((Component)((RaycastHit)(ref val3)).transform).tag.StartsWith("PlayerRagdoll")) { val3 = (RaycastHit)field2.GetValue(turret); Rigidbody component2 = ((Component)((RaycastHit)(ref val3)).transform).GetComponent<Rigidbody>(); if ((Object)(object)component2 != (Object)null) { component2.AddForce(((Vector3)(ref val)).normalized * 42f, (ForceMode)1); } } } } val = Quaternion.Euler(0f, num / 6f, 0f) * val; } return null; } public static EnemyAICollisionDetect CheckForEnemiesInLineOfSight(Turret turret, float radius = 2f, bool angleRangeCheck = false) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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) //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_0042: 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) Vector3 forward = turret.aimPoint.forward; forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward; List<EnemyAICollisionDetect> enemyTargets = Plugin.GetEnemyTargets(Plugin.GetTargets(((Component)turret).GetComponent<FAIR_AI>(), turret.aimPoint.position, forward, radius)); if (enemyTargets == null || !enemyTargets.Any()) { return null; } return enemyTargets[0]; } public static bool SetTargetToEnemyBody(ref Turret __instance) { if (!((Object)(object)__instance == (Object)null)) { FieldInfo field = typeof(Turret).GetField("targetingDeadPlayer", BindingFlags.Instance | BindingFlags.NonPublic); FAIR_AI component = ((Component)__instance).gameObject.GetComponent<FAIR_AI>(); if ((Object)(object)component.targetWithRotation != (Object)null) { if (!((Object)(object)((Component)component.targetWithRotation).GetComponent<EnemyAICollisionDetect>() != (Object)null)) { if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null) { if (__instance.targetPlayerWithRotation.isPlayerDead) { if (!(bool)field.GetValue(__instance)) { field.SetValue(__instance, true); } if ((Object)(object)__instance.targetPlayerWithRotation.deadBody != (Object)null) { __instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.deadBody.bodyParts[5]).transform; } } else { field.SetValue(__instance, false); __instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.gameplayCamera).transform; } } return false; } if (((Component)component.targetWithRotation).GetComponent<EnemyAICollisionDetect>().mainScript.isEnemyDead) { if (!(bool)field.GetValue(__instance)) { field.SetValue(__instance, true); } } else if ((Object)(object)__instance.targetPlayerWithRotation == (Object)null) { field.SetValue(__instance, false); __instance.targetTransform = ((Component)component.targetWithRotation).transform; } } else if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null) { if (__instance.targetPlayerWithRotation.isPlayerDead) { if (!(bool)field.GetValue(__instance)) { field.SetValue(__instance, true); } if ((Object)(object)__instance.targetPlayerWithRotation.deadBody != (Object)null) { __instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.deadBody.bodyParts[5]).transform; } } else { field.SetValue(__instance, false); __instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.gameplayCamera).transform; } } } return false; } public static bool TurnTowardsTargetEnemyIfHasLOS(ref Turret __instance) { //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0180: 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_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: 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) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null)) { FAIR_AI component = ((Component)__instance).GetComponent<FAIR_AI>(); Type typeFromHandle = typeof(Turret); FieldInfo field = typeFromHandle.GetField("targetingDeadPlayer", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeFromHandle.GetField("hasLineOfSight", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field3 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic); bool flag = true; if ((Object)(object)__instance.targetTransform != (Object)null && (Object)(object)__instance.centerPoint != (Object)null && (Object)(object)__instance.forwardFacingPos != (Object)null && Vector3.Angle(__instance.targetTransform.position - __instance.centerPoint.position, __instance.forwardFacingPos.forward) > __instance.rotationRange) { flag = false; } EnemyAICollisionDetect val = CheckForEnemiesInLineOfSight(__instance, 15f); if ((Object)(object)val == (Object)null) { flag = false; } if (flag) { __instance.targetTransform = ((Component)val.mainScript).transform; field2.SetValue(__instance, true); field3.SetValue(__instance, 0f); __instance.tempTransform.position = __instance.targetTransform.position; Transform tempTransform = __instance.tempTransform; tempTransform.position -= Vector3.up * 0.15f; __instance.turnTowardsObjectCompass.LookAt(__instance.tempTransform); return false; } bool flag2 = true; if ((bool)field.GetValue(__instance) || Vector3.Angle(__instance.targetTransform.position - __instance.centerPoint.position, __instance.forwardFacingPos.forward) > __instance.rotationRange) { flag2 = false; } if (Physics.Linecast(__instance.aimPoint.position, __instance.targetTransform.position, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1)) { flag2 = false; } if (flag2) { field2.SetValue(__instance, true); field3.SetValue(__instance, 0f); __instance.tempTransform.position = __instance.targetTransform.position; Transform tempTransform2 = __instance.tempTransform; tempTransform2.position -= Vector3.up * 0.15f; __instance.turnTowardsObjectCompass.LookAt(__instance.tempTransform); return false; } if ((bool)field2.GetValue(__instance)) { field2.SetValue(__instance, false); field3.SetValue(__instance, 0f); } if (!((NetworkBehaviour)__instance).IsServer) { return false; } field3.SetValue(__instance, (float)field3.GetValue(__instance) + Time.deltaTime); if ((float)field3.GetValue(__instance) >= 2f) { field3.SetValue(__instance, 0f); Plugin.logger.LogInfo((object)"Turret: LOS timer ended on server. checking for new player target"); PlayerControllerB val2 = CheckForPlayersInLOS(__instance); if ((Object)(object)val2 != (Object)null) { __instance.targetPlayerWithRotation = val2; __instance.SwitchTargetedPlayerClientRpc((int)val2.playerClientId, false); Plugin.logger.LogInfo((object)"Turret: Got new player target"); } else { Plugin.logger.LogInfo((object)"Turret: No new player to target; returning to detection mode."); __instance.targetPlayerWithRotation = null; __instance.RemoveTargetedPlayerClientRpc(); } } if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null) { return false; } if ((bool)field2.GetValue(__instance)) { field2.SetValue(__instance, false); field3.SetValue(__instance, 0f); } if (!((NetworkBehaviour)__instance).IsServer) { return false; } field3.SetValue(__instance, (float)field3.GetValue(__instance) + Time.deltaTime); if ((float)field3.GetValue(__instance) >= 2f) { field3.SetValue(__instance, 0f); Plugin.logger.LogInfo((object)"Turret: LOS timer ended on server. checking for new enemy target"); EnemyAICollisionDetect val3 = CheckForEnemiesInLineOfSight(__instance, 15f); if ((Object)(object)val3 != (Object)null) { component.targetWithRotation = val3.mainScript; component.SwitchedTargetedEnemyClientRpc(__instance, val3.mainScript); Plugin.logger.LogInfo((object)"Turret: Got new enemy target"); } else { Plugin.logger.LogInfo((object)"Turret: No new enemy to target; returning to detection mode."); component.targetWithRotation = null; component.RemoveTargetedEnemyClientRpc(); } } } return false; } } namespace FairAI { public class FAIR_AI : NetworkBehaviour { public EnemyAI targetWithRotation; public Dictionary<int, GameObject> targets; private void Awake() { targetWithRotation = null; } [ClientRpc] public void SwitchedTargetedEnemyClientRpc(Turret turret, EnemyAI enemy, bool setModeToCharging = false) { targetWithRotation = enemy; if (setModeToCharging) { typeof(Turret).GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(turret, new object[1] { 2 }); } } [ClientRpc] public void RemoveTargetedEnemyClientRpc() { targetWithRotation = null; } } [BepInPlugin("GoldenKitten.FairAI", "Fair AI", "1.5.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private const string modGUID = "GoldenKitten.FairAI"; private const string modName = "Fair AI"; private const string modVersion = "1.5.1"; private Harmony harmony = new Harmony("GoldenKitten.FairAI"); private static float onMeshThreshold = 3f; public static Plugin Instance; public static ManualLogSource logger; public static List<EnemyType> enemies; public static List<Item> items; public static List<EnemyType> enemyList; public static List<Item> itemList; public static List<float> turretSettings; public static Dictionary<string, float[]> speeds; public static Dictionary<int, Vector3> positions; public static Dictionary<int, float> sinkingValues; public static Dictionary<int, float> sinkingProgress; public static Assembly surfacedAssembly; public static Assembly turretSettingsAssembly; public static PropertyInfo tsBoundConfig; public const string ltModID = "evaisa.lethalthings"; public const string surfacedModID = "Surfaced"; public static bool playersEnteredInside = false; public static bool surfacedEnabled = false; public static bool lethalThingsEnabled = false; public static bool turretSettingsEnabled = false; public static bool lethalConfigEnabled = false; public static bool roundHasStarted = false; public static int wallsAndEnemyLayerMask = 524288; public static int enemyMask = 524288; public static int allHittablesMask; private async void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } enemies = new List<EnemyType>(); items = new List<Item>(); itemList = new List<Item>(); enemyList = new List<EnemyType>(); speeds = new Dictionary<string, float[]>(); positions = new Dictionary<int, Vector3>(); sinkingProgress = new Dictionary<int, float>(); turretSettings = new List<float>(); sinkingValues = new Dictionary<int, float>(); surfacedAssembly = null; harmony = new Harmony("GoldenKitten.FairAI"); logger = Logger.CreateLogSource("GoldenKitten.FairAI"); harmony.PatchAll(typeof(Plugin)); CreateHarmonyPatch(harmony, typeof(RoundManager), "Start", null, typeof(RoundManagerPatch), "PatchStart", isPrefix: false); CreateHarmonyPatch(harmony, typeof(StartOfRound), "Start", null, typeof(StartOfRoundPatch), "PatchStart", isPrefix: false); CreateHarmonyPatch(harmony, typeof(StartOfRound), "Update", null, typeof(StartOfRoundPatch), "PatchUpdate", isPrefix: false); CreateHarmonyPatch(harmony, typeof(QuicksandTrigger), "OnTriggerStay", new Type[1] { typeof(Collider) }, typeof(QuickSandPatch), "OnTriggerStayPatch", isPrefix: true); CreateHarmonyPatch(harmony, typeof(QuicksandTrigger), "OnTriggerExit", new Type[1] { typeof(Collider) }, typeof(QuickSandPatch), "OnTriggerExitPatch", isPrefix: true); CreateHarmonyPatch(harmony, typeof(Turret), "Update", null, typeof(TurretAIPatch), "PatchUpdate", isPrefix: true); CreateHarmonyPatch(harmony, typeof(Turret), "CheckForPlayersInLineOfSight", new Type[2] { typeof(float), typeof(bool) }, typeof(TurretAIPatch), "CheckForTargetsInLOS", isPrefix: true); CreateHarmonyPatch(harmony, typeof(Turret), "SetTargetToPlayerBody", null, typeof(TurretAIPatch), "SetTargetToEnemyBody", isPrefix: true); CreateHarmonyPatch(harmony, typeof(Turret), "TurnTowardsTargetIfHasLOS", null, typeof(TurretAIPatch), "TurnTowardsTargetEnemyIfHasLOS", isPrefix: true); CreateHarmonyPatch(harmony, typeof(Landmine), "SpawnExplosion", new Type[8] { typeof(Vector3), typeof(bool), typeof(float), typeof(float), typeof(int), typeof(float), typeof(GameObject), typeof(bool) }, typeof(MineAIPatch), "PatchSpawnExplosion", isPrefix: false); CreateHarmonyPatch(harmony, typeof(Landmine), "OnTriggerEnter", null, typeof(MineAIPatch), "PatchOnTriggerEnter", isPrefix: false); CreateHarmonyPatch(harmony, typeof(Landmine), "OnTriggerExit", null, typeof(MineAIPatch), "PatchOnTriggerExit", isPrefix: false); CreateHarmonyPatch(harmony, typeof(Landmine), "Detonate", null, typeof(MineAIPatch), "DetonatePatch", isPrefix: false); await WaitForProcess(1); GetTurretSettings(); logger.LogInfo((object)"Fair AI initiated!"); } public static void ImmortalAffected() { if (!GetBool("General", "ImmortalAffected")) { enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType)) where (Object)(object)e != (Object)null && e.canDie select e).ToList(); } } public static float[] SpeedAndAccelerationEnemyList(EnemyAICollisionDetect enemy) { if ((Object)(object)enemy != (Object)null) { EnemyAI mainScript = enemy.mainScript; if ((Object)(object)enemy.mainScript != (Object)null) { EnemyType enemyType = mainScript.enemyType; _ = enemyType.enemyName; if ((Object)(object)enemyType != (Object)null) { if (GetSpeeds(enemy) == null) { NavMeshAgent componentInChildren = ((Component)mainScript).GetComponentInChildren<NavMeshAgent>(); if ((Object)(object)componentInChildren != (Object)null) { speeds.Add(enemyType.enemyName, new float[2] { componentInChildren.speed, componentInChildren.acceleration }); return speeds[enemyType.enemyName]; } speeds.Add(enemyType.enemyName, new float[2] { 1f, 1f }); return speeds[enemyType.enemyName]; } return speeds[enemyType.enemyName]; } } else { logger.LogWarning((object)"No EnemyAI To Get Speeds!"); } } else { logger.LogWarning((object)"No EnemyCollision To Get Speeds!"); } return new float[2] { 1f, 1f }; } public static float[] GetSpeeds(EnemyAICollisionDetect enemy) { EnemyType enemyType = enemy.mainScript.enemyType; if (speeds.TryGetValue(enemyType.enemyName, out var value)) { return value; } logger.LogWarning((object)("Speeds missing on: " + enemyType.enemyName)); return null; } public static void GetTurretSettings() { if (turretSettingsEnabled) { object value = tsBoundConfig.GetValue(null); Type type = null; if (value != null) { type = value.GetType(); if (type == null) { logger.LogInfo((object)"Bound Config Type not gotten!"); } } else { logger.LogInfo((object)"Unable to get BoundConfig"); } FieldInfo field = type.GetField("turretDamage", BindingFlags.Instance | BindingFlags.Public); if (field != null) { object value2 = field.GetValue(value); float item = (int)(value2?.GetType().GetProperty("Value"))?.GetValue(value2); turretSettings.Add(item); } FieldInfo field2 = type.GetField("turretFireRate", BindingFlags.Instance | BindingFlags.Public); if (field2 != null) { object value3 = field2.GetValue(value); float item2 = (float)(value3?.GetType().GetProperty("Value"))?.GetValue(value3); turretSettings.Add(item2); } FieldInfo field3 = type.GetField("turretWarmupTime", BindingFlags.Instance | BindingFlags.Public); if (field3 != null) { object value4 = field3.GetValue(value); float item3 = (float)(value4?.GetType().GetProperty("Value"))?.GetValue(value4); turretSettings.Add(item3); } FieldInfo field4 = type.GetField("turretRotateTimer", BindingFlags.Instance | BindingFlags.Public); if (field4 != null) { object value5 = field4.GetValue(value); float item4 = (float)(value5?.GetType().GetProperty("Value"))?.GetValue(value5); turretSettings.Add(item4); } FieldInfo field5 = type.GetField("turretRotationRange", BindingFlags.Instance | BindingFlags.Public); if (field5 != null) { object value6 = field5.GetValue(value); float item5 = (float)(value6?.GetType().GetProperty("Value"))?.GetValue(value6); turretSettings.Add(item5); } FieldInfo field6 = type.GetField("turretIdleRotationSpeed", BindingFlags.Instance | BindingFlags.Public); if (field6 != null) { object value7 = field6.GetValue(value); float item6 = (float)(value7?.GetType().GetProperty("Value"))?.GetValue(value7); turretSettings.Add(item6); } FieldInfo field7 = type.GetField("turretFiringRotationSpeed", BindingFlags.Instance | BindingFlags.Public); if (field7 != null) { object value8 = field7.GetValue(value); float item7 = (float)(value8?.GetType().GetProperty("Value"))?.GetValue(value8); turretSettings.Add(item7); } FieldInfo field8 = type.GetField("turretBerzerkRotationSpeed", BindingFlags.Instance | BindingFlags.Public); if (field8 != null) { object value9 = field8.GetValue(value); float item8 = (float)(value9?.GetType().GetProperty("Value"))?.GetValue(value9); turretSettings.Add(item8); } logger.LogInfo((object)("Got Turret Settings: " + turretSettings.Count)); } else { turretSettings = new List<float>(); } } public static async Task<IEnumerable<int>> WaitForProcess(int waitTime) { await Task.Delay(waitTime); bool flag = false; while (!flag) { await Instance.DelayedInitialization(); flag = true; } return new List<int>(); } private async Task DelayedInitialization() { await Task.Run(delegate { TryLoadLethalThings(); TryLoadSurfaced(); TryLoadTurretSettings(); TryLoadLethalConfig(); logger.LogInfo((object)"Optional Components initiated!"); }); } private void TryLoadLethalThings() { try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); Assembly assembly = null; Assembly[] array = assemblies; foreach (Assembly assembly2 in array) { if (assembly2.GetName().Name == "LethalThings") { assembly = assembly2; break; } } if (assembly != null) { Type type = assembly.GetType("LethalThings.RoombaAI"); if (type != null && BoombaPatch.enabled) { CreateHarmonyPatch(harmony, type, "Start", null, typeof(BoombaPatch), "PatchStart", isPrefix: false); CreateHarmonyPatch(harmony, type, "DoAIInterval", null, typeof(BoombaPatch), "PatchDoAIInterval", isPrefix: false); lethalThingsEnabled = true; logger.LogInfo((object)"LethalThings Component Initiated!"); } } else { logger.LogWarning((object)"LethalThings assembly not found. Skipping optional patch."); } } catch (Exception ex) { logger.LogError((object)("An error occurred while trying to apply patches for LethalThings: " + ex.Message)); } } private void TryLoadSurfaced() { try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetName().Name == "Surfaced") { surfacedAssembly = assembly; break; } } if (surfacedAssembly != null) { Type type = surfacedAssembly.GetType("Seamine"); Type type2 = surfacedAssembly.GetType("Bertha"); if (type != null) { if (SurfacedMinePatch.enabled) { CreateHarmonyPatch(harmony, type, "OnTriggerEnter", new Type[1] { typeof(Collider) }, typeof(SurfacedMinePatch), "PatchOnTriggerEnter", isPrefix: false); surfacedEnabled = true; logger.LogInfo((object)"Surfaced Component Seamine Initiated!"); } } else { logger.LogInfo((object)"Surfaced Component Seamine Not Found!"); } if (type2 != null) { if (SurfacedMinePatch.enabled) { CreateHarmonyPatch(harmony, type2, "OnTriggerEnter", new Type[1] { typeof(Collider) }, typeof(SurfacedMinePatch), "PatchBerthaOnTriggerEnter", isPrefix: false); surfacedEnabled = true; logger.LogInfo((object)"Surfaced Component Bertha Initiated!"); } } else { logger.LogInfo((object)"Surfaced Component Bertha Not Found!"); } } else { logger.LogWarning((object)"Surfaced assembly not found. Skipping optional patch."); } } catch (Exception ex) { logger.LogError((object)("An error occurred while trying to apply patches for Surfaced: " + ex.Message)); } } private void TryLoadTurretSettings() { try { Assembly assembly = Assembly.Load("TheNameIsTyler.TurretSettings"); if (assembly != null) { turretSettingsAssembly = assembly; Type type = turretSettingsAssembly.GetType("TurretSettings.TurretSettings"); if (type != null) { PropertyInfo property = type.GetProperty("BoundConfig", BindingFlags.Static | BindingFlags.NonPublic); if (property != null) { tsBoundConfig = property; turretSettingsEnabled = true; logger.LogInfo((object)"TurretSettings Component Initiated!"); } else { logger.LogWarning((object)"TurretSettings config not found. Skipping optional patch."); } } else { logger.LogWarning((object)"TurretSettings type not found. Skipping optional patch."); } } else { logger.LogWarning((object)"TurretSettings assembly not found. Skipping optional patch."); } } catch (Exception ex) { logger.LogError((object)("An error occurred while trying to apply patches for TurretSettings: " + ex.Message)); } } private void TryLoadLethalConfig() { try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); Assembly assembly = null; Assembly[] array = assemblies; foreach (Assembly assembly2 in array) { if (assembly2.GetName().Name == "LethalConfig") { assembly = assembly2; break; } } if (assembly != null) { if (assembly.GetType("LethalConfig.LethalConfigManager") != null) { lethalConfigEnabled = true; logger.LogInfo((object)"LethalConfig Component Initiated!"); } } else { logger.LogWarning((object)"LethalConfig assembly not found. Skipping optional patch."); } } catch (Exception ex) { logger.LogError((object)("An error occurred while trying to apply patches for LethalConfig: " + ex.Message)); } } public static List<PlayerControllerB> GetActivePlayers() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; List<PlayerControllerB> list = new List<PlayerControllerB>(); PlayerControllerB[] array = allPlayerScripts; foreach (PlayerControllerB val in array) { if ((Object)val != (Object)null && !val.isPlayerDead && ((Behaviour)val).isActiveAndEnabled && val.isPlayerControlled) { list.Add(val); } } return list; } public static bool AllowFairness(Vector3 position) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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) if ((Object)(object)StartOfRound.Instance != (Object)null && Can("CheckForPlayersInside") && StartOfRound.Instance.shipHasLanded) { if (IsAPlayersOutside()) { if (!(position.y > -80f)) { Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds; if (!((Bounds)(ref bounds)).Contains(position)) { goto IL_0055; } } return true; } goto IL_0055; } return true; IL_0055: return playersEnteredInside; } public static bool IsAPlayersOutside() { if (StartOfRound.Instance.shipHasLanded) { List<PlayerControllerB> activePlayers = GetActivePlayers(); for (int i = 0; i < activePlayers.Count; i++) { if (!activePlayers[i].isInsideFactory) { return true; } } } return false; } public static bool IsAPlayerInsideShip() { if (StartOfRound.Instance.shipHasLanded) { List<PlayerControllerB> activePlayers = GetActivePlayers(); for (int i = 0; i < activePlayers.Count; i++) { if (activePlayers[i].isInHangarShipRoom) { return true; } } } return false; } public static bool IsAPlayerInsideDungeon() { if (StartOfRound.Instance.shipHasLanded) { List<PlayerControllerB> activePlayers = GetActivePlayers(); for (int i = 0; i < activePlayers.Count; i++) { if (activePlayers[i].isInsideFactory) { return true; } } } return false; } public static bool CanMob(string parentIdentifier, string identifier, string mobName) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown string text = RemoveInvalidCharacters(mobName).ToUpper(); if (((BaseUnityPlugin)Instance).Config[new ConfigDefinition("Mobs", parentIdentifier)].BoxedValue.ToString().ToUpper().Equals("TRUE")) { foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys) { if (RemoveInvalidCharacters(key.Key.ToUpper()).Equals(RemoveInvalidCharacters(text + identifier).ToUpper())) { return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Equals("TRUE"); } } return false; } return false; } public static bool Can(string identifier) { foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys) { if (RemoveInvalidCharacters(key.Key.ToUpper()).Equals(RemoveInvalidCharacters(identifier.ToUpper()))) { return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Equals("TRUE"); } } return false; } public static int GetInt(string parentIdentifier, string identifier) { try { int.TryParse(((BaseUnityPlugin)Instance).Config[parentIdentifier, identifier].BoxedValue.ToString(), out var result); return result; } catch { return 1; } } public static float GetFloat(string parentIdentifier, string identifier) { try { float.TryParse(((BaseUnityPlugin)Instance).Config[parentIdentifier, identifier].BoxedValue.ToString(), out var result); return result; } catch { return 1f; } } public static bool GetBool(string parentIdentifier, string identifier) { if (RemoveInvalidCharacters(((BaseUnityPlugin)Instance).Config[parentIdentifier, identifier].BoxedValue.ToString()).ToUpper().Equals("TRUE")) { return true; } return false; } public static string RemoveWhitespaces(string source) { return string.Join("", source.Split((string[]?)null, StringSplitOptions.RemoveEmptyEntries)); } public static string RemoveSpecialCharacters(string source) { StringBuilder stringBuilder = new StringBuilder(); foreach (char c in source) { if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { stringBuilder.Append(c); } } return stringBuilder.ToString(); } public static string RemoveInvalidCharacters(string source) { return RemoveWhitespaces(RemoveSpecialCharacters(source)); } public static Type FindType(string fullName) { try { if ((from a in AppDomain.CurrentDomain.GetAssemblies() where !a.IsDynamic select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName)) != null) { return (from a in AppDomain.CurrentDomain.GetAssemblies() where !a.IsDynamic select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName)); } } catch { return null; } return null; } public static void CreateHarmonyPatch(Harmony harmony, Type typeToPatch, string methodToPatch, Type[] parameters, Type patchType, string patchMethod, bool isPrefix, bool isTranspiler = false) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown if (typeToPatch == null || patchType == null) { logger.LogInfo((object)"Type is either incorrect or does not exist!"); return; } MethodInfo methodInfo = AccessTools.Method(typeToPatch, methodToPatch, parameters, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(patchType, patchMethod, (Type[])null, (Type[])null); if (isTranspiler) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null); } else if (isPrefix) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } public static bool IsAgentOnNavMesh(GameObject agentObject) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0024: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) Vector3 position = agentObject.transform.position; NavMeshHit val = default(NavMeshHit); if (NavMesh.SamplePosition(position, ref val, onMeshThreshold, -1) && Mathf.Approximately(position.x, ((NavMeshHit)(ref val)).position.x) && Mathf.Approximately(position.z, ((NavMeshHit)(ref val)).position.z)) { return position.y >= ((NavMeshHit)(ref val)).position.y; } return false; } public static bool AttackTargets(FAIR_AI turret_ai, Vector3 aimPoint, Vector3 forward, float range) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return HitTargets(GetTargets(turret_ai, aimPoint, forward, range), forward); } public static List<GameObject> GetTargets(FAIR_AI turret_ai, Vector3 aimPoint, Vector3 forward, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: 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_0109: Unknown result type (might be due to invalid IL or missing references) List<GameObject> list = new List<GameObject>(); RaycastHit[] array = Physics.RaycastAll(new Ray(aimPoint, forward), range, -5, (QueryTriggerInteraction)2); Array.Sort(array, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance)); Vector3 val = aimPoint + forward * range; IHittable val2 = default(IHittable); EnemyAI val5 = default(EnemyAI); for (int i = 0; i < array.Length; i++) { _ = ((Component)((RaycastHit)(ref array[i])).transform).gameObject; Transform transform = ((RaycastHit)(ref array[i])).transform; if (((Component)transform).TryGetComponent<IHittable>(ref val2)) { EnemyAI val3 = null; EnemyAICollisionDetect val4 = (EnemyAICollisionDetect)(object)((val2 is EnemyAICollisionDetect) ? val2 : null); if (val4 != null) { val3 = val4.mainScript; } if ((Object)(object)val3 != (Object)null && !val3.isEnemyDead && val3.enemyHP > 0) { list.Add(((Component)transform).gameObject); } if (!(val2 is EnemyAICollisionDetect) && !(val2 is PlayerControllerB) && !(val2 is SandSpiderWebTrap)) { if (!(val2 is Turret)) { val2.Hit(1, val, (PlayerControllerB)null, false, -1); } else if (GetBool("TurretConfig", "HitOtherTurrets")) { val2.Hit(1, val, (PlayerControllerB)null, false, -1); } } val = ((RaycastHit)(ref array[i])).point; } else { if (((Component)transform).TryGetComponent<EnemyAI>(ref val5) && !val5.isEnemyDead && val5.enemyHP > 0) { list.Add(((Component)val5).gameObject); val = ((RaycastHit)(ref array[i])).point; } val = ((RaycastHit)(ref array[i])).point; } } return list; } public static List<EnemyAICollisionDetect> GetEnemyTargets(List<GameObject> originalTargets) { List<EnemyAICollisionDetect> hits = new List<EnemyAICollisionDetect>(); originalTargets.ForEach(delegate(GameObject t) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)t != (Object)null && t.GetComponent<IHittable>() != null) { IHittable component = t.GetComponent<IHittable>(); if (component is EnemyAICollisionDetect) { EnemyAICollisionDetect item = (EnemyAICollisionDetect)component; hits.Add(item); } } }); return hits; } public static bool HitTargets(List<GameObject> targets, Vector3 forward) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) bool hits = false; if (!targets.Any()) { return hits; } targets.ForEach(delegate(GameObject t) { //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Expected O, but got Unknown //IL_008b: 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_005c: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)t != (Object)null) { if ((Object)(object)t.GetComponent<EnemyAI>() != (Object)null) { EnemyAI component = t.GetComponent<EnemyAI>(); int @int = GetInt("TurretConfig", "Enemy Damage"); if (CanMob("TurretDamageAllMobs", ".Turret Damage", component.enemyType.enemyName)) { if (component is NutcrackerEnemyAI) { if (((EnemyAI)(NutcrackerEnemyAI)component).currentBehaviourStateIndex > 0) { component.HitEnemyOnLocalClient(@int, default(Vector3), (PlayerControllerB)null, false, -1); hits = true; } } else { component.HitEnemyOnLocalClient(@int, default(Vector3), (PlayerControllerB)null, false, -1); hits = true; } } } else if (t.GetComponent<IHittable>() != null) { IHittable component2 = t.GetComponent<IHittable>(); if (component2 is EnemyAICollisionDetect) { EnemyAICollisionDetect val = (EnemyAICollisionDetect)component2; int int2 = GetInt("TurretConfig", "Enemy Damage"); if (CanMob("TurretDamageAllMobs", ".Turret Damage", val.mainScript.enemyType.enemyName)) { if (val.mainScript is NutcrackerEnemyAI) { if (((EnemyAI)(NutcrackerEnemyAI)val.mainScript).currentBehaviourStateIndex > 0) { val.mainScript.HitEnemyOnLocalClient(int2, default(Vector3), (PlayerControllerB)null, false, -1); hits = true; } } else { val.mainScript.HitEnemyOnLocalClient(int2, default(Vector3), (PlayerControllerB)null, false, -1); hits = true; } } } else if (!(component2 is PlayerControllerB)) { if (!(component2 is Turret)) { component2.Hit(1, forward, (PlayerControllerB)null, true, -1); hits = true; } else if (GetBool("TurretConfig", "HitOtherTurrets")) { component2.Hit(1, forward, (PlayerControllerB)null, true, -1); hits = true; } } } } }); return hits; } } public static class PluginInfo { public const string PLUGIN_GUID = "FairAI"; public const string PLUGIN_NAME = "FairAI"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace FairAI.Patches { public static class BoombaPatch { private static bool? _enabled; public static bool enabled { get { if (!_enabled.HasValue) { _enabled = Chainloader.PluginInfos.ContainsKey("evaisa.lethalthings"); } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void PatchStart(ref RoombaAI __instance) { ((Component)__instance).gameObject.AddComponent<BoombaTimer>(); } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void PatchDoAIInterval(ref RoombaAI __instance) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.AllowFairness(((Component)__instance).transform.position) || !Plugin.IsAgentOnNavMesh(((Component)__instance).gameObject) || (((EnemyAI)__instance).currentSearch == null && !((EnemyAI)__instance).movingTowardsTargetPlayer) || (!__instance.mineAudio.isPlaying && !__instance.mineFarAudio.isPlaying) || !((Component)__instance).GetComponent<BoombaTimer>().IsActiveBomb()) { return; } Vector3 val = ((Component)__instance).transform.position + Vector3.up; Collider[] array = Physics.OverlapSphere(val, 6f, 2621448, (QueryTriggerInteraction)2); for (int i = 0; i < array.Length; i++) { float num = Vector3.Distance(val, ((Component)array[i]).transform.position); if ((num > 4f && Physics.Linecast(val, ((Component)array[i]).transform.position + Vector3.up * 0.3f, 256, (QueryTriggerInteraction)1)) || !((Object)(object)((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>() != (Object)null)) { continue; } EnemyAICollisionDetect component = ((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>(); if (!((Object)(object)((Component)component.mainScript).gameObject != (Object)(object)((Component)__instance).gameObject) || !Plugin.CanMob("BoombaAllMobs", ".Boomba", component.mainScript.enemyType.enemyName)) { continue; } if ((Object)(object)component != (Object)null && ((NetworkBehaviour)component.mainScript).IsOwner && !component.mainScript.isEnemyDead) { Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab, val, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true); if (num < 3f) { component.mainScript.KillEnemyOnOwnerClient(true); } else if (num < 6f) { component.mainScript.HitEnemyOnLocalClient(2, default(Vector3), (PlayerControllerB)null, false, -1); } } if (((NetworkBehaviour)__instance).IsServer) { ((EnemyAI)__instance).KillEnemy(true); } else { ((EnemyAI)__instance).KillEnemyServerRpc(true); } } } } internal class EnemyAIPatch { } internal class MineAIPatch { [CompilerGenerated] private sealed class <WaitForUpdate>d__3 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public float waitTime; public Landmine mine; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <WaitForUpdate>d__3(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(waitTime); <>1__state = 1; return true; case 1: <>1__state = -1; if (!((Object)(object)mine == (Object)null)) { if ((Object)(object)((Component)mine).GetComponent<NetworkObject>() != (Object)null) { ((Component)mine).GetComponent<NetworkObject>().Despawn(true); } else { Object.Destroy((Object)(object)((Component)mine).gameObject); } } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static void PatchOnTriggerEnter(ref Landmine __instance, Collider other, ref float ___pressMineDebounceTimer) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (Plugin.AllowFairness(((Component)__instance).transform.position)) { EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper())) { ___pressMineDebounceTimer = 0.5f; __instance.PressMineServerRpc(); } } } public static void PatchOnTriggerExit(ref Landmine __instance, Collider other, ref bool ___sendingExplosionRPC) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (Plugin.AllowFairness(((Component)__instance).transform.position)) { EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper()) && !__instance.hasExploded) { __instance.SetOffMineAnimation(); ___sendingExplosionRPC = true; __instance.ExplodeMineServerRpc(); } } } public static void DetonatePatch(ref Landmine __instance) { if (!((Object)(object)__instance == (Object)null)) { ((MonoBehaviour)__instance).StartCoroutine(WaitForUpdate(1.5f, __instance)); } } [IteratorStateMachine(typeof(<WaitForUpdate>d__3))] public static IEnumerator WaitForUpdate(float waitTime, Landmine mine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <WaitForUpdate>d__3(0) { waitTime = waitTime, mine = mine }; } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void PatchSpawnExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, int nonLethalDamage = 50, float physicsForce = 0f, GameObject overridePrefab = null, bool goThroughCar = false) { //IL_0000: 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_0022: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0198: 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) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) Collider[] array = Physics.OverlapSphere(explosionPosition, 6f, 2621448, (QueryTriggerInteraction)2); for (int i = 0; i < array.Length; i++) { float num = Vector3.Distance(explosionPosition, ((Component)array[i]).transform.position); if (num > 4f && Physics.Linecast(explosionPosition, ((Component)array[i]).transform.position + Vector3.up * 0.3f, 256, (QueryTriggerInteraction)1)) { continue; } if (Plugin.surfacedEnabled && Plugin.surfacedAssembly != null) { Type type = Plugin.surfacedAssembly.GetType("Seamine"); if (type != null && (Object)(object)((Component)array[i]).gameObject.GetComponent(type) != (Object)null) { Component component = ((Component)array[i]).gameObject.GetComponent(type); FieldInfo field = type.GetField("mineActivated", BindingFlags.Instance | BindingFlags.NonPublic); if (!(bool)type.GetField("hasExploded", BindingFlags.Instance | BindingFlags.Public).GetValue(component) || !(bool)field.GetValue(component)) { break; } if (Plugin.AllowFairness(component.transform.position)) { type.GetMethod("TriggerMineOnLocalClientByExiting", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(component, new object[0]); } } } if (!((Object)(object)((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>() != (Object)null)) { continue; } EnemyAICollisionDetect component2 = ((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component2 != (Object)null && ((NetworkBehaviour)component2.mainScript).IsOwner && !component2.mainScript.isEnemyDead) { if (num < killRange) { component2.mainScript.HitEnemyOnLocalClient(component2.mainScript.enemyHP, default(Vector3), (PlayerControllerB)null, false, -1); } else if (num < damageRange) { component2.mainScript.HitEnemyOnLocalClient(Mathf.RoundToInt(Plugin.GetFloat("ExplosionConfig", "Damage")), default(Vector3), (PlayerControllerB)null, false, -1); } } } } } internal class QuickSandPatch { public static bool OnTriggerStayPatch(ref QuicksandTrigger __instance, Collider other) { if (Plugin.GetBool("Quick Sand Config", "Disable Quicksand Interactions")) { return true; } if (__instance.isWater) { if (!((Component)other).gameObject.CompareTag("Player") && (Object)(object)((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>() == (Object)null) { return false; } if ((Object)(object)((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>() != (Object)null) { return false; } PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>(); if ((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && (Object)(object)component != (Object)null && (Object)(object)component.underwaterCollider != (Object)(object)__instance) { component.underwaterCollider = ((Component)__instance).gameObject.GetComponent<Collider>(); return false; } } if (!__instance.isWater && !((Component)other).gameObject.CompareTag("Player") && (Object)(object)((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>() == (Object)null) { return false; } PlayerControllerB component2 = ((Component)other).gameObject.GetComponent<PlayerControllerB>(); if ((Object)(object)component2 != (Object)null) { if ((Object)(object)component2 != (Object)(object)GameNetworkManager.Instance.localPlayerController) { return false; } if ((__instance.isWater && component2.isIns