Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of DefenceBot v0.1.3
BepInEx/plugins/DefenceBot/DefenceBot.dll
Decompiled 6 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Photon.Pun; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace DefenceBotMod; [HarmonyPatch(typeof(ItemDrone), "TargetFindPlayer")] internal static class DefenceBotAcquisition { private static float SearchRadius(ItemDrone drone) { if (!Object.op_Implicit((Object)(object)((Component)drone).GetComponent<DefenceBotFollow>())) { return 1f; } float num = DefenceBotPlugin.FollowDistance.Value; if (float.IsNaN(num) || float.IsInfinity(num)) { num = 2f; } return Mathf.Max(3f, Mathf.Clamp(num, 1.2f, 4f) + 0.75f); } private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> source) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(source); int num = 0; for (int i = 1; i < list.Count - 1; i++) { CodeInstruction val = list[i]; if (!(val.opcode != OpCodes.Ldc_R4) && val.operand is float && (float)val.operand == 1f && !(list[i - 1].opcode != OpCodes.Callvirt) && object.Equals(list[i - 1].operand, AccessTools.PropertyGetter(typeof(Transform), "position"))) { val.opcode = OpCodes.Ldarg_0; val.operand = null; list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DefenceBotAcquisition), "SearchRadius", (Type[])null, (Type[])null))); num++; i++; } } if (num != 1) { throw new InvalidOperationException("Native drone player-search radius changed; Defence Bot patch was not applied."); } return list; } } public sealed class DefenceBotController : MonoBehaviour { private const BindingFlags Fields = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly FieldInfo EnemyDead = typeof(EnemyHealth).GetField("dead", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo EnemyDying = typeof(EnemyHealth).GetField("deadImpulse", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo EnemyCurrentHealth = typeof(EnemyHealth).GetField("healthCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo EnemySpawned = typeof(EnemyParent).GetField("Spawned", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo FollowPlayer = typeof(ItemDrone).GetField("playerAvatarTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo DroneActivated = typeof(ItemDrone).GetField("itemActivated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo DroneConnected = typeof(ItemDrone).GetField("magnetActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo PlayerDead = typeof(PlayerAvatar).GetField("deadSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo ItemEquipped = typeof(ItemEquippable).GetField("isEquipped", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private ItemDrone drone; private ItemBattery battery; private ItemToggle itemToggle; private ItemEquippable equippable; private PhysGrabObject grab; private PhotonView view; private DefenceBotFollow follow; private Transform muzzle; private Transform turret; private LineRenderer shotLine; private Material shotMaterial; private EnemyHealth[] enemies = (EnemyHealth[])(object)new EnemyHealth[0]; private EnemyHealth currentTarget; private float nextScan; private float nextTargetScan; private float nextShot; private float beamUntil; private float nextAimSync; private float aimExpires; private Vector3 aimPoint; private bool aiming; private bool ready; public int ShotsFired { get; private set; } private float AttackRange => SafeFloat(DefenceBotPlugin.Range.Value, 12f, 1f, 50f); private void Start() { drone = ((Component)this).GetComponent<ItemDrone>(); battery = ((Component)this).GetComponent<ItemBattery>(); itemToggle = ((Component)this).GetComponent<ItemToggle>(); equippable = ((Component)this).GetComponent<ItemEquippable>(); grab = ((Component)this).GetComponent<PhysGrabObject>(); view = ((Component)this).GetComponent<PhotonView>(); follow = ((Component)this).GetComponent<DefenceBotFollow>(); Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "Muzzle") { muzzle = val; } if (((Object)val).name == "Defence Bot Turret") { turret = val; } } if (!Object.op_Implicit((Object)(object)drone) || !Object.op_Implicit((Object)(object)battery) || !Object.op_Implicit((Object)(object)itemToggle) || !Object.op_Implicit((Object)(object)equippable) || !Object.op_Implicit((Object)(object)grab) || !Object.op_Implicit((Object)(object)view) || !Object.op_Implicit((Object)(object)follow) || !Object.op_Implicit((Object)(object)muzzle) || !Object.op_Implicit((Object)(object)turret) || EnemyDead == null || EnemyDying == null || EnemyCurrentHealth == null || EnemySpawned == null || FollowPlayer == null || DroneActivated == null || DroneConnected == null || PlayerDead == null || ItemEquipped == null) { DefenceBotPlugin.LogWarning("Defence Bot combat disabled: required native components or fields are missing."); ((Behaviour)this).enabled = false; } else { CreateShotLine(); ready = true; } } private void FixedUpdate() { if (ready && SemiFunc.IsMasterClientOrSingleplayer() && SemiFunc.RunIsLevel() && !(bool)ItemEquipped.GetValue(equippable) && grab.playerGrabbing.Count == 0 && !(battery.batteryLife <= 0f) && itemToggle.toggleState && (bool)DroneActivated.GetValue(drone)) { grab.OverrideZeroGravity(0.1f); grab.OverrideDrag(1f, 0.1f); grab.OverrideAngularDrag(10f, 0.1f); } } private void Update() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: 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_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)shotLine) && ((Renderer)shotLine).enabled && Time.time >= beamUntil) { ((Renderer)shotLine).enabled = false; } if (!ready) { return; } if (!SemiFunc.IsMasterClientOrSingleplayer()) { if (Time.time >= aimExpires) { aiming = false; } TurnTurret(); return; } if (!CanFire()) { currentTarget = null; SetAim(active: false, Vector3.zero); TurnTurret(); return; } if (Time.time >= nextScan) { enemies = Object.FindObjectsOfType<EnemyHealth>(); nextScan = Time.time + 0.5f; } Vector3 hitPoint; if (Time.time >= nextTargetScan || !IsEligibleEnemy(currentTarget)) { currentTarget = FindTarget(out hitPoint); nextTargetScan = Time.time + 0.15f; } if (!Object.op_Implicit((Object)(object)currentTarget)) { SetAim(active: false, Vector3.zero); TurnTurret(); return; } SetAim(active: true, TargetPoint(currentTarget)); TurnTurret(); if (!(Time.time < nextShot) && AimAligned() && TryGetClearShot(currentTarget, out hitPoint)) { nextShot = Time.time + SafeFloat(DefenceBotPlugin.FireInterval.Value, 0.8f, 0.1f, 10f); Vector3 val = hitPoint - muzzle.position; Vector3 normalized = ((Vector3)(ref val)).normalized; if (SemiFunc.IsMultiplayer()) { view.RPC("DefenceBotShotRPC", (RpcTarget)0, new object[1] { hitPoint }); } else { DefenceBotShotRPC(hitPoint, default(PhotonMessageInfo)); } currentTarget.Hurt(Mathf.Clamp(DefenceBotPlugin.Damage.Value, 1, 1000), normalized); ShotsFired++; } } private void SetAim(bool active, Vector3 point) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0080: Unknown result type (might be due to invalid IL or missing references) bool flag = aiming != active; aiming = active; aimPoint = point; if (active) { follow.AimAt(point); } else { follow.ClearAim(); } if (SemiFunc.IsMultiplayer() && (flag || (active && Time.time >= nextAimSync))) { nextAimSync = Time.time + 0.15f; view.RPC("DefenceBotAimRPC", (RpcTarget)1, new object[2] { active, point }); } } private void TurnTurret() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0095: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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) Quaternion val = Quaternion.identity; if (aiming) { Vector3 val2 = turret.parent.InverseTransformDirection(aimPoint - turret.position); float y = val2.y; Vector2 val3 = new Vector2(val2.x, val2.z); float num = (0f - Mathf.Atan2(y, ((Vector2)(ref val3)).magnitude)) * 57.29578f; val = Quaternion.Euler(Mathf.Clamp(num, -65f, 65f), 0f, 0f); } turret.localRotation = Quaternion.RotateTowards(turret.localRotation, val, 240f * Time.deltaTime); } private bool AimAligned() { //IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.ProjectOnPlane(aimPoint - ((Component)this).transform.position, Vector3.up); Vector3 val2 = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up); if (((Vector3)(ref val)).sqrMagnitude > 0.001f && Vector3.Angle(val2, val) <= 8f) { return Vector3.Angle(turret.forward, aimPoint - muzzle.position) <= 8f; } return false; } private static Vector3 TargetPoint(EnemyHealth health) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Enemy component = ((Component)health).GetComponent<Enemy>(); if (!Object.op_Implicit((Object)(object)component.CenterTransform)) { return ((Component)component).transform.position; } return component.CenterTransform.position; } private bool CanFire() { //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected I4, but got Unknown if (!((Behaviour)drone).enabled || !SemiFunc.RunIsLevel() || (bool)ItemEquipped.GetValue(equippable) || grab.playerGrabbing.Count != 0 || !itemToggle.toggleState || battery.batteryLife <= 0f || !(bool)DroneActivated.GetValue(drone) || !(bool)DroneConnected.GetValue(drone)) { return false; } int num = (int)drone.currentState; if (num != 2 && num != 3) { return false; } object? value = FollowPlayer.GetValue(drone); PlayerAvatar val = (PlayerAvatar)((value is PlayerAvatar) ? value : null); if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeInHierarchy) { return !(bool)PlayerDead.GetValue(val); } return false; } private EnemyHealth FindTarget(out Vector3 hitPoint) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_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_00fa: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0182: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) hitPoint = Vector3.zero; EnemyHealth result = null; float num = AttackRange * AttackRange; EnemyHealth[] array = enemies; foreach (EnemyHealth val in array) { if (!IsEligibleEnemy(val)) { continue; } Vector3 val2 = TargetPoint(val); Vector3 val3 = val2 - muzzle.position; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (sqrMagnitude >= num) { continue; } Vector3 origin = muzzle.position; Vector3 val4 = Vector3.ProjectOnPlane(val2 - ((Component)this).transform.position, Vector3.up); if (((Vector3)(ref val4)).sqrMagnitude > 0.001f) { Quaternion val5 = Quaternion.LookRotation(val4, Vector3.up) * Quaternion.Inverse(((Component)this).transform.rotation); Vector3 val6 = ((Component)this).transform.position + val5 * (turret.position - ((Component)this).transform.position); Vector3 val7 = val2 - val6; float num2 = Mathf.Abs(val7.y); Vector2 val8 = new Vector2(val7.x, val7.z); float num3 = Mathf.Atan2(num2, ((Vector2)(ref val8)).magnitude) * 57.29578f; if (num3 > 65f) { continue; } if (((Vector3)(ref val7)).sqrMagnitude > 0.001f) { Quaternion val9 = Quaternion.LookRotation(((Vector3)(ref val7)).normalized, Vector3.up) * Quaternion.Inverse(turret.rotation); origin = val6 + val9 * (muzzle.position - turret.position); } } if (TryGetShotFrom(val, origin, out var hitPoint2)) { result = val; num = sqrMagnitude; hitPoint = hitPoint2; } } return result; } private bool IsEligibleEnemy(EnemyHealth health) { //IL_006e: 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_007c: Invalid comparison between Unknown and I4 //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Invalid comparison between Unknown and I4 if (!Object.op_Implicit((Object)(object)health) || !((Behaviour)health).enabled || !((Component)health).gameObject.activeInHierarchy || (bool)EnemyDead.GetValue(health) || (bool)EnemyDying.GetValue(health) || (int)EnemyCurrentHealth.GetValue(health) <= 0) { return false; } Enemy component = ((Component)health).GetComponent<Enemy>(); if (!Object.op_Implicit((Object)(object)component) || !((Behaviour)component).enabled || (int)component.CurrentState == 0 || (int)component.CurrentState == 1 || (int)component.CurrentState == 11) { return false; } EnemyParent componentInParent = ((Component)component).GetComponentInParent<EnemyParent>(); if (Object.op_Implicit((Object)(object)componentInParent)) { return (bool)EnemySpawned.GetValue(componentInParent); } return false; } private bool TryGetClearShot(EnemyHealth health, out Vector3 hitPoint) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return TryGetShotFrom(health, muzzle.position, out hitPoint); } private bool TryGetShotFrom(EnemyHealth health, Vector3 origin, out Vector3 hitPoint) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0030: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_007b: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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_015f: 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_016d: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: 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_01f7: Unknown result type (might be due to invalid IL or missing references) hitPoint = Vector3.zero; if (!IsEligibleEnemy(health)) { return false; } Enemy component = ((Component)health).GetComponent<Enemy>(); Vector3 val = (Object.op_Implicit((Object)(object)component.CenterTransform) ? component.CenterTransform.position : ((Component)component).transform.position); Vector3 val2 = val - origin; float magnitude = ((Vector3)(ref val2)).magnitude; if (!Finite(origin) || !Finite(val) || magnitude < 0.05f || magnitude > AttackRange) { return false; } LayerMask val3 = SemiFunc.LayerMaskGetShouldHits(); Vector3 val4 = origin - ((Component)this).transform.position; if (((Vector3)(ref val4)).sqrMagnitude > 0.001f) { RaycastHit[] array = Physics.RaycastAll(((Component)this).transform.position, ((Vector3)(ref val4)).normalized, ((Vector3)(ref val4)).magnitude, LayerMask.op_Implicit(val3), (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val5 = array[i]; if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider) && !IsSelf(((RaycastHit)(ref val5)).collider)) { return false; } } } Collider[] array2 = Physics.OverlapSphere(origin, 0.025f, LayerMask.op_Implicit(val3), (QueryTriggerInteraction)1); foreach (Collider collider in array2) { if (!IsSelf(collider) && (Object)(object)ColliderEnemy(collider) != (Object)(object)health) { return false; } } RaycastHit[] array3 = Physics.RaycastAll(origin, val2 / magnitude, magnitude + 0.1f, LayerMask.op_Implicit(val3), (QueryTriggerInteraction)1); Array.Sort(array3, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance)); RaycastHit[] array4 = array3; for (int num = 0; num < array4.Length; num++) { RaycastHit val6 = array4[num]; if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val6)).collider) && !IsSelf(((RaycastHit)(ref val6)).collider)) { if ((Object)(object)ColliderEnemy(((RaycastHit)(ref val6)).collider) != (Object)(object)health) { return false; } hitPoint = ((RaycastHit)(ref val6)).point; return true; } } return false; } private bool IsSelf(Collider collider) { if (!((Object)(object)((Component)collider).transform == (Object)(object)((Component)this).transform)) { return ((Component)collider).transform.IsChildOf(((Component)this).transform); } return true; } private static EnemyHealth ColliderEnemy(Collider collider) { EnemyHealth componentInParent = ((Component)collider).GetComponentInParent<EnemyHealth>(); if (Object.op_Implicit((Object)(object)componentInParent)) { return componentInParent; } EnemyRigidbody componentInParent2 = ((Component)collider).GetComponentInParent<EnemyRigidbody>(); if (Object.op_Implicit((Object)(object)componentInParent2) && Object.op_Implicit((Object)(object)componentInParent2.enemy)) { return ((Component)componentInParent2.enemy).GetComponent<EnemyHealth>(); } EnemyParent componentInParent3 = ((Component)collider).GetComponentInParent<EnemyParent>(); if (!Object.op_Implicit((Object)(object)componentInParent3)) { return null; } return ((Component)componentInParent3).GetComponentInChildren<EnemyHealth>(); } [PunRPC] public void DefenceBotAimRPC(bool active, Vector3 point, PhotonMessageInfo info) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_0027: 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) if (!SemiFunc.MasterOnlyRPC(info) || !ready || !Finite(point)) { return; } if (active) { Vector3 val = point - ((Component)this).transform.position; if (((Vector3)(ref val)).sqrMagnitude > 3025f) { return; } } aiming = active; aimPoint = point; aimExpires = Time.time + 0.75f; } [PunRPC] public void DefenceBotShotRPC(Vector3 hitPoint, PhotonMessageInfo info) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.MasterOnlyRPC(info) && ready && Object.op_Implicit((Object)(object)muzzle) && Finite(hitPoint)) { Vector3 val = hitPoint - muzzle.position; if (!(((Vector3)(ref val)).sqrMagnitude > 3025f) && Object.op_Implicit((Object)(object)shotLine)) { shotLine.SetPosition(0, muzzle.position); shotLine.SetPosition(1, hitPoint); ((Renderer)shotLine).enabled = true; beamUntil = Time.time + 0.08f; } } } private void CreateShotLine() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color"); if (Object.op_Implicit((Object)(object)val)) { GameObject val2 = new GameObject("Defence Bot Shot Beam"); val2.transform.SetParent(((Component)this).transform, false); shotLine = val2.AddComponent<LineRenderer>(); shotMaterial = new Material(val); shotMaterial.color = new Color(0.15f, 1f, 1f, 1f); ((Renderer)shotLine).sharedMaterial = shotMaterial; shotLine.useWorldSpace = true; shotLine.positionCount = 2; shotLine.startWidth = 0.035f; shotLine.endWidth = 0.015f; shotLine.startColor = new Color(0.3f, 1f, 1f, 1f); shotLine.endColor = new Color(0.1f, 0.75f, 1f, 0.7f); ((Renderer)shotLine).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)shotLine).receiveShadows = false; ((Renderer)shotLine).enabled = false; } } private void OnDisable() { if (Object.op_Implicit((Object)(object)shotLine)) { ((Renderer)shotLine).enabled = false; } currentTarget = null; aiming = false; if (Object.op_Implicit((Object)(object)follow)) { follow.ClearAim(); } } private void OnDestroy() { if (Object.op_Implicit((Object)(object)shotMaterial)) { Object.Destroy((Object)(object)shotMaterial); } } private static float SafeFloat(float value, float fallback, float minimum, float maximum) { if (!float.IsNaN(value) && !float.IsInfinity(value)) { return Mathf.Clamp(value, minimum, maximum); } return fallback; } private static bool Finite(Vector3 value) { if (!float.IsNaN(value.x) && !float.IsNaN(value.y) && !float.IsNaN(value.z) && !float.IsInfinity(value.x) && !float.IsInfinity(value.y)) { return !float.IsInfinity(value.z); } return false; } } internal static class DefenceBotFactory { internal const string ItemId = "Item Defence Bot"; internal const string PrefabPath = "Items/CaspiDefenceBot"; private static GameObject holder; private static bool reportedFailure; internal static GameObject Prefab { get; private set; } internal static Item Definition { get; private set; } internal static void Validate() { if (AccessTools.Method(typeof(EnemyHealth), "Hurt", (Type[])null, (Type[])null) == null || AccessTools.Field(typeof(ItemDrone), "targetPlayers") == null || AccessTools.Field(typeof(RunManager), "singleplayerPool") == null || AccessTools.Field(typeof(RunManager), "multiplayerPool") == null) { throw new InvalidOperationException("Required native drone, combat or item-pool APIs are missing."); } } internal static void EnsureRegistered(StatsManager stats) { if (!Object.op_Implicit((Object)(object)stats)) { return; } try { if (!Object.op_Implicit((Object)(object)Prefab) || !Object.op_Implicit((Object)(object)Definition)) { Build(); } if (stats.itemDictionary.TryGetValue("Item Defence Bot", out var value) && (Object)(object)value != (Object)(object)Definition) { throw new InvalidOperationException("Another mod has registered Item Defence Bot"); } stats.itemDictionary["Item Defence Bot"] = Definition; RegisterPools(); } catch (Exception ex) { if (!reportedFailure) { reportedFailure = true; DefenceBotPlugin.LogWarning("Defence Bot registration failed: " + ex); } } } private static void Build() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Expected O, but got Unknown GameObject val = Resources.Load<GameObject>("Items/Item Drone Feather"); ItemAttributes val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemAttributes>() : null); if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.item) || !Object.op_Implicit((Object)(object)val2.item.value) || !Object.op_Implicit((Object)(object)val.GetComponent<ItemDrone>()) || !Object.op_Implicit((Object)(object)val.GetComponent<ItemDroneFeather>()) || !Object.op_Implicit((Object)(object)val.GetComponent<ItemBattery>()) || !Object.op_Implicit((Object)(object)val.GetComponent<ItemToggle>())) { throw new InvalidOperationException("Native Feather Drone template is unavailable."); } GameObject val3 = new GameObject("Defence Bot prefab holder"); val3.SetActive(false); ((Object)val3).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)val3); try { GameObject val4 = Object.Instantiate<GameObject>(val, val3.transform, false); ((Object)val4).name = "Item Defence Bot"; Object.DestroyImmediate((Object)(object)val4.GetComponent<ItemDroneFeather>()); ItemDrone component = val4.GetComponent<ItemDrone>(); component.targetPlayers = true; component.targetEnemies = false; component.targetValuables = false; component.targetNonValuables = false; Item val5 = Object.Instantiate<Item>(val2.item); ((Object)val5).name = "Item Defence Bot"; ((Object)val5).hideFlags = (HideFlags)61; val5.itemName = "Defence Bot"; val5.itemNameLocalized = null; val5.description = "A hovering companion that follows a player and shoots visible nearby enemies. Activate beside a player to deploy."; val5.disabled = false; val5.minPlayerCount = 1; val5.maxAmountInShop = 1; val5.maxPurchase = false; val5.value = Object.Instantiate<Value>(val2.item.value); ((Object)val5.value).name = "Defence Bot Price"; ((Object)val5.value).hideFlags = (HideFlags)61; if (DefenceBotPlugin.BasePrice.Value > 0) { val5.value.valueMin = (val5.value.valueMax = DefenceBotPlugin.BasePrice.Value); } val5.prefab = new PrefabRef(); ((PrefabRef<GameObject>)(object)val5.prefab).SetPrefab(val4, "Items/CaspiDefenceBot"); val4.GetComponent<ItemAttributes>().item = val5; Transform val6 = DefenceBotVisual.Attach(val4); if (!Object.op_Implicit((Object)(object)val6)) { throw new InvalidOperationException("Defence Bot muzzle could not be built."); } val4.AddComponent<DefenceBotFollow>(); val4.AddComponent<DefenceBotController>(); val4.SetActive(true); holder = val3; Definition = val5; Prefab = val4; } catch { Object.Destroy((Object)(object)val3); throw; } } internal static void RegisterPools() { if (Object.op_Implicit((Object)(object)RunManager.instance) && Object.op_Implicit((Object)(object)Prefab)) { Dictionary<string, Object> dictionary = AccessTools.Field(typeof(RunManager), "singleplayerPool").GetValue(RunManager.instance) as Dictionary<string, Object>; object? value = AccessTools.Field(typeof(RunManager), "multiplayerPool").GetValue(RunManager.instance); MultiplayerPool val = (MultiplayerPool)((value is MultiplayerPool) ? value : null); if (dictionary != null) { dictionary["Items/CaspiDefenceBot"] = (Object)(object)Prefab; } if (val != null) { val.ResourceCache["Items/CaspiDefenceBot"] = Prefab; } } } } [HarmonyPatch(typeof(StatsManager), "LoadItemsFromFolder")] internal static class DefenceBotRegistration { private static void Postfix(StatsManager __instance) { DefenceBotFactory.EnsureRegistered(__instance); } } [HarmonyPatch(typeof(LevelGenerator), "Start")] internal static class DefenceBotScenePool { private static void Postfix() { DefenceBotFactory.RegisterPools(); } } [HarmonyPatch(typeof(PrefabRef<GameObject>), "get_Prefab")] internal static class DefenceBotPrefabReference { private static bool Prefix(PrefabRef<GameObject> __instance, ref GameObject __result) { if (__instance.ResourcePath != "Items/CaspiDefenceBot" || !Object.op_Implicit((Object)(object)DefenceBotFactory.Prefab)) { return true; } __result = DefenceBotFactory.Prefab; return false; } } [HarmonyPatch(typeof(MultiplayerPool), "Instantiate")] internal static class DefenceBotNetworkPrefab { private static void Prefix(MultiplayerPool __instance, string __0) { if (__0 == "Items/CaspiDefenceBot" && Object.op_Implicit((Object)(object)DefenceBotFactory.Prefab)) { __instance.ResourceCache[__0] = DefenceBotFactory.Prefab; } } } public sealed class DefenceBotFollow : MonoBehaviour { private const BindingFlags Fields = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly FieldInfo TargetField = typeof(ItemDrone).GetField("playerAvatarTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo ActiveField = typeof(ItemDrone).GetField("itemActivated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo ConnectedField = typeof(ItemDrone).GetField("magnetActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo DeadField = typeof(PlayerAvatar).GetField("deadSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo DisabledField = typeof(PlayerAvatar).GetField("isDisabled", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly MethodInfo TeleportEffect = typeof(ItemDrone).GetMethod("TeleportEffect", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private ItemDrone drone; private ItemToggle toggle; private ItemBattery battery; private ItemEquippable equippable; private PhysGrabObject grab; private Rigidbody body; private RigidbodyConstraints previousConstraints; private bool ready; private bool constraintsChanged; private bool warned; private float bodyRadius = 0.44f; private float blockedFor; private float recoverAfter; private Vector3 aimPoint; private float aimUntil; private Vector3 lastHeading = Vector3.forward; private Vector3 lastClearDestination; private bool hasLastClearDestination; public bool IsFollowing { get; private set; } public Vector3 DesiredPosition { get; private set; } public int RecoveryCount { get; private set; } public PlayerAvatar FollowedPlayer { get; private set; } private float FollowDistance { get { float value = DefenceBotPlugin.FollowDistance.Value; if (!float.IsNaN(value) && !float.IsInfinity(value)) { return Mathf.Clamp(value, 1.2f, 4f); } return 2f; } } private void Start() { //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0123: 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_0132: 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_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) drone = ((Component)this).GetComponent<ItemDrone>(); toggle = ((Component)this).GetComponent<ItemToggle>(); battery = ((Component)this).GetComponent<ItemBattery>(); equippable = ((Component)this).GetComponent<ItemEquippable>(); grab = ((Component)this).GetComponent<PhysGrabObject>(); body = ((Component)this).GetComponent<Rigidbody>(); if (!Object.op_Implicit((Object)(object)drone) || !Object.op_Implicit((Object)(object)toggle) || !Object.op_Implicit((Object)(object)battery) || !Object.op_Implicit((Object)(object)equippable) || !Object.op_Implicit((Object)(object)grab) || !Object.op_Implicit((Object)(object)body) || TargetField == null || ActiveField == null || ConnectedField == null || DeadField == null || DisabledField == null) { DefenceBotPlugin.LogWarning("Defence Bot distance control is unavailable; native drone movement retained."); ((Behaviour)this).enabled = false; return; } Transform val = ((Component)this).transform.Find("Valuable Box Collider"); BoxCollider val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<BoxCollider>() : null); if (Object.op_Implicit((Object)(object)val2)) { Vector3 val3 = Vector3.Scale(val2.size, ((Component)val2).transform.lossyScale) * 0.5f; Vector2 val4 = new Vector2(val3.x, val3.z); bodyRadius = Mathf.Clamp(((Vector2)(ref val4)).magnitude + 0.035f, 0.3f, 0.65f); } DesiredPosition = body.position; ready = true; } public void AimAt(Vector3 worldPoint) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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) if (Finite(worldPoint)) { aimPoint = worldPoint; aimUntil = Time.time + 1f; } } public void ClearAim() { aimUntil = 0f; } internal bool RunNativeOrFollow() { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected I4, but got Unknown //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0150: 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_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: 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_0222: 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) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_020b: 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_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: 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_029c: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: 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_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: 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_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_03ec: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_0413: Unknown result type (might be due to invalid IL or missing references) //IL_0418: 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_0325: Unknown result type (might be due to invalid IL or missing references) //IL_042a: 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_0567: Unknown result type (might be due to invalid IL or missing references) //IL_056e: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_057d: Unknown result type (might be due to invalid IL or missing references) //IL_0585: Unknown result type (might be due to invalid IL or missing references) //IL_058a: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_0591: Unknown result type (might be due to invalid IL or missing references) //IL_0596: Unknown result type (might be due to invalid IL or missing references) //IL_059b: Unknown result type (might be due to invalid IL or missing references) //IL_0600: Unknown result type (might be due to invalid IL or missing references) //IL_0607: Unknown result type (might be due to invalid IL or missing references) //IL_060c: Unknown result type (might be due to invalid IL or missing references) //IL_0611: Unknown result type (might be due to invalid IL or missing references) //IL_0619: Unknown result type (might be due to invalid IL or missing references) //IL_0621: Unknown result type (might be due to invalid IL or missing references) //IL_0626: Unknown result type (might be due to invalid IL or missing references) //IL_0630: 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_0657: Unknown result type (might be due to invalid IL or missing references) //IL_0662: Unknown result type (might be due to invalid IL or missing references) //IL_0667: Unknown result type (might be due to invalid IL or missing references) //IL_066c: Unknown result type (might be due to invalid IL or missing references) //IL_0671: 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_05d4: Unknown result type (might be due to invalid IL or missing references) //IL_05ce: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04a9: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04b5: Unknown result type (might be due to invalid IL or missing references) //IL_04bd: Unknown result type (might be due to invalid IL or missing references) //IL_04bf: Unknown result type (might be due to invalid IL or missing references) //IL_04cc: Unknown result type (might be due to invalid IL or missing references) //IL_04dc: Unknown result type (might be due to invalid IL or missing references) //IL_0676: Unknown result type (might be due to invalid IL or missing references) //IL_05d9: 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_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_05e9: Unknown result type (might be due to invalid IL or missing references) //IL_05f3: Unknown result type (might be due to invalid IL or missing references) //IL_05f8: Unknown result type (might be due to invalid IL or missing references) //IL_05fd: Unknown result type (might be due to invalid IL or missing references) //IL_0560: Unknown result type (might be due to invalid IL or missing references) //IL_0565: Unknown result type (might be due to invalid IL or missing references) //IL_0688: Unknown result type (might be due to invalid IL or missing references) //IL_068d: Unknown result type (might be due to invalid IL or missing references) //IL_0692: Unknown result type (might be due to invalid IL or missing references) //IL_0697: 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_06b5: Unknown result type (might be due to invalid IL or missing references) //IL_06ba: Unknown result type (might be due to invalid IL or missing references) //IL_06c7: Unknown result type (might be due to invalid IL or missing references) //IL_051b: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Unknown result type (might be due to invalid IL or missing references) if (!((Behaviour)this).enabled || !ready || !SemiFunc.IsMasterClientOrSingleplayer()) { return true; } if (!SemiFunc.RunIsLevel() || equippable.IsEquipped() || !toggle.toggleState || battery.batteryLife <= 0f || !(bool)ActiveField.GetValue(drone)) { StopFollowing(); return true; } if (grab.playerGrabbing.Count != 0) { StopFollowing(); return false; } int num = (int)drone.currentState; object? value = TargetField.GetValue(drone); PlayerAvatar val = (PlayerAvatar)((value is PlayerAvatar) ? value : null); if ((num != 2 && num != 3) || !(bool)ConnectedField.GetValue(drone) || !Object.op_Implicit((Object)(object)val) || !((Component)val).gameObject.activeInHierarchy || (bool)DeadField.GetValue(val) || (bool)DisabledField.GetValue(val)) { StopFollowing(); return true; } FollowedPlayer = val; IsFollowing = true; if (!constraintsChanged) { previousConstraints = body.constraints; Rigidbody obj = body; obj.constraints = (RigidbodyConstraints)(obj.constraints | 0x50); Vector3 val2 = Vector3.ProjectOnPlane(((Component)body).transform.forward, Vector3.up); if (((Vector3)(ref val2)).sqrMagnitude < 0.001f) { val2 = Vector3.forward; } body.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up); body.angularVelocity = Vector3.zero; constraintsChanged = true; } grab.OverrideZeroGravity(0.1f); grab.OverrideDrag(1f, 0.1f); grab.OverrideAngularDrag(10f, 0.1f); Transform val3 = (Object.op_Implicit((Object)(object)val.PlayerVisionTarget) ? val.PlayerVisionTarget.VisionTransform : null); Vector3 val4 = (Object.op_Implicit((Object)(object)val3) ? (val3.position - Vector3.up * 0.35f) : (((Component)val).transform.position + Vector3.up)); if (Object.op_Implicit((Object)(object)drone.playerTumbleTarget)) { val4 = ((Component)drone.playerTumbleTarget).transform.position + Vector3.up * 0.65f; } float num2 = float.PositiveInfinity; RaycastHit[] array = Physics.RaycastAll(val4 + Vector3.up * 0.75f, Vector3.down, 3f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetShouldHits()), (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val5 = array[i]; if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider) && !Self(((RaycastHit)(ref val5)).collider) && !IsPlayer(((RaycastHit)(ref val5)).collider, val) && !(((RaycastHit)(ref val5)).normal.y < 0.5f) && !(((RaycastHit)(ref val5)).distance >= num2)) { num2 = ((RaycastHit)(ref val5)).distance; val4.y = Mathf.Max(val4.y, ((RaycastHit)(ref val5)).point.y + bodyRadius + 0.08f); } } Vector3 val6 = Vector3.ProjectOnPlane(((Component)val).transform.forward, Vector3.up); if (((Vector3)(ref val6)).sqrMagnitude < 0.001f && Object.op_Implicit((Object)(object)val3)) { val6 = Vector3.ProjectOnPlane(val3.forward, Vector3.up); } if (((Vector3)(ref val6)).sqrMagnitude < 0.001f) { val6 = lastHeading; } ((Vector3)(ref val6)).Normalize(); lastHeading = val6; Vector3 val7 = Vector3.Cross(Vector3.up, val6); Vector3 result; bool flag = ChoosePosition(val4, val6, val7, val, out result); DesiredPosition = (flag ? result : body.position); float num3 = Vector3.Distance(body.position, val4); Vector3 val8 = DesiredPosition - body.position; bool flag2 = flag && PathBlocked(body.position, DesiredPosition, null, bodyRadius); blockedFor = ((flag2 && num3 > 4f) ? (blockedFor + Time.fixedDeltaTime) : 0f); if (flag && Time.time >= recoverAfter && (num3 > 18f || blockedFor > 1.5f)) { Vector3 position = body.position; Quaternion val9 = Quaternion.LookRotation(val6, Vector3.up); grab.Teleport(result, val9); body.velocity = Vector3.zero; body.angularVelocity = Vector3.zero; if (TeleportEffect != null && Object.op_Implicit((Object)(object)drone.teleportParticles)) { TeleportEffect.Invoke(drone, new object[2] { position, result }); } RecoveryCount++; recoverAfter = Time.time + 2f; blockedFor = 0f; val8 = Vector3.zero; } Vector3 val10 = Vector3.ClampMagnitude(val8 * 3f, 6f); Vector3 val11 = Vector3.ProjectOnPlane(body.position - val4, Vector3.up); float num4 = Mathf.Min(1.2f, FollowDistance * 0.65f); if (((Vector3)(ref val11)).magnitude < num4) { Vector3 val12 = ((((Vector3)(ref val11)).sqrMagnitude > 0.001f) ? ((Vector3)(ref val11)).normalized : val7); val10 += val12 * (num4 - ((Vector3)(ref val11)).magnitude) * 5f; } val10 = AvoidCollision(Vector3.ClampMagnitude(val10, 6f)); body.AddForce(Vector3.ClampMagnitude((val10 - body.velocity) * 7f, 24f), (ForceMode)5); Vector3 val13 = ((Time.time < aimUntil) ? Vector3.ProjectOnPlane(aimPoint - body.position, Vector3.up) : val6); if (((Vector3)(ref val13)).sqrMagnitude > 0.001f) { Quaternion val14 = Quaternion.LookRotation(((Vector3)(ref val13)).normalized, Vector3.up); body.angularVelocity = Vector3.zero; body.MoveRotation(Quaternion.RotateTowards(body.rotation, val14, 300f * Time.fixedDeltaTime)); } body.WakeUp(); return false; } private bool ChoosePosition(Vector3 anchor, Vector3 forward, Vector3 right, PlayerAvatar player, out Vector3 result) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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_00dc: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: 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_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: 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_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017a: 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_01ff: 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_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[8] { right * 0.866f - forward * 0.5f, -right * 0.866f - forward * 0.5f, -forward, right, -right, forward * 0.5f + right * 0.866f, forward * 0.5f - right * 0.866f, forward }; float followDistance = FollowDistance; float num = Mathf.Min(1.2f, followDistance); for (int i = 0; i < 3; i++) { float num2 = Mathf.Lerp(followDistance, num, (float)i * 0.5f); Vector3[] array2 = array; for (int j = 0; j < array2.Length; j++) { Vector3 val = array2[j]; Vector3 val2 = anchor + ((Vector3)(ref val)).normalized * num2; if (!PositionBlocked(val2) && !PathBlocked(anchor, val2, player, 0.05f)) { lastClearDestination = val2; hasLastClearDestination = true; result = val2; return true; } } } Vector3 val3 = lastClearDestination - anchor; Vector3 val4 = Vector3.ProjectOnPlane(val3, Vector3.up); float magnitude = ((Vector3)(ref val4)).magnitude; if (hasLastClearDestination && magnitude >= num && magnitude <= followDistance + 0.5f && Mathf.Abs(val3.y) <= 0.75f && !PositionBlocked(lastClearDestination) && !PathBlocked(anchor, lastClearDestination, player, 0.05f) && !PathBlocked(body.position, lastClearDestination, null, bodyRadius)) { result = lastClearDestination; return true; } result = body.position; return false; } private bool PositionBlocked(Vector3 position) { //IL_0000: 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) Collider[] array = Physics.OverlapSphere(position, bodyRadius, LayerMask.op_Implicit(SemiFunc.LayerMaskGetShouldHits()), (QueryTriggerInteraction)1); foreach (Collider val in array) { if (Object.op_Implicit((Object)(object)val) && !Self(val)) { return true; } } return false; } private bool PathBlocked(Vector3 start, Vector3 end, PlayerAvatar ignorePlayer, float radius) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = end - start; if (((Vector3)(ref val)).sqrMagnitude < 0.001f) { return false; } RaycastHit[] array = Physics.SphereCastAll(start, radius, ((Vector3)(ref val)).normalized, ((Vector3)(ref val)).magnitude, LayerMask.op_Implicit(SemiFunc.LayerMaskGetShouldHits()), (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val2 = array[i]; if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider) && !Self(((RaycastHit)(ref val2)).collider) && !IsPlayer(((RaycastHit)(ref val2)).collider, ignorePlayer)) { return true; } } return false; } private Vector3 AvoidCollision(Vector3 velocity) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0134: 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_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) if (((Vector3)(ref velocity)).sqrMagnitude < 0.001f) { return velocity; } float num = ((Vector3)(ref velocity)).magnitude * Time.fixedDeltaTime + 0.12f; RaycastHit[] array = Physics.SphereCastAll(body.position, bodyRadius, ((Vector3)(ref velocity)).normalized, num, LayerMask.op_Implicit(SemiFunc.LayerMaskGetShouldHits()), (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val = array[i]; if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider) || Self(((RaycastHit)(ref val)).collider)) { continue; } if (((RaycastHit)(ref val)).distance <= 0.001f) { Vector3 val2 = body.position - ((RaycastHit)(ref val)).collider.ClosestPoint(body.position); if (((Vector3)(ref val2)).sqrMagnitude < 0.001f) { Vector3 position = body.position; Bounds bounds = ((RaycastHit)(ref val)).collider.bounds; val2 = position - ((Bounds)(ref bounds)).center; } if (Vector3.Dot(velocity, val2) > 0f) { continue; } } Vector3 normal = ((RaycastHit)(ref val)).normal; if (((Vector3)(ref normal)).sqrMagnitude < 0.1f) { return Vector3.zero; } if (Vector3.Dot(velocity, ((RaycastHit)(ref val)).normal) < 0f) { velocity = Vector3.ProjectOnPlane(velocity, ((RaycastHit)(ref val)).normal); } } return velocity; } private bool Self(Collider collider) { if (!((Object)(object)((Component)collider).transform == (Object)(object)((Component)this).transform)) { return ((Component)collider).transform.IsChildOf(((Component)this).transform); } return true; } private bool IsPlayer(Collider collider, PlayerAvatar player) { if (!Object.op_Implicit((Object)(object)player)) { return false; } if ((Object)(object)((Component)collider).GetComponentInParent<PlayerAvatar>() == (Object)(object)player) { return true; } PlayerHealthGrab componentInParent = ((Component)collider).GetComponentInParent<PlayerHealthGrab>(); if (Object.op_Implicit((Object)(object)componentInParent) && (Object)(object)componentInParent.playerAvatar == (Object)(object)player) { return true; } PlayerController componentInParent2 = ((Component)collider).GetComponentInParent<PlayerController>(); if (Object.op_Implicit((Object)(object)componentInParent2) && (Object)(object)componentInParent2.playerAvatarScript == (Object)(object)player) { return true; } PlayerTumble componentInParent3 = ((Component)collider).GetComponentInParent<PlayerTumble>(); if (Object.op_Implicit((Object)(object)componentInParent3)) { return (Object)(object)drone.playerTumbleTarget == (Object)(object)componentInParent3; } return false; } private void StopFollowing() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) IsFollowing = false; FollowedPlayer = null; blockedFor = 0f; if (constraintsChanged && Object.op_Implicit((Object)(object)body)) { body.constraints = previousConstraints; } constraintsChanged = false; } private void OnDisable() { StopFollowing(); } internal void DisableAfterFailure(Exception ex) { StopFollowing(); ((Behaviour)this).enabled = false; if (!warned) { warned = true; DefenceBotPlugin.LogWarning("Defence Bot distance control stopped; native drone movement retained: " + ex.Message); } } private static bool Finite(Vector3 value) { if (!float.IsNaN(value.x) && !float.IsNaN(value.y) && !float.IsNaN(value.z) && !float.IsInfinity(value.x) && !float.IsInfinity(value.y)) { return !float.IsInfinity(value.z); } return false; } } [HarmonyPatch(typeof(ItemDrone), "FixedUpdate")] internal static class DefenceBotNativeFollow { private static bool Prefix(ItemDrone __instance) { DefenceBotFollow component = ((Component)__instance).GetComponent<DefenceBotFollow>(); if (!Object.op_Implicit((Object)(object)component)) { return true; } try { return component.RunNativeOrFollow(); } catch (Exception ex) { component.DisableAfterFailure(ex); return true; } } } [BepInPlugin("caspi.defencebot", "Defence Bot", "0.1.3")] public sealed class DefenceBotPlugin : BaseUnityPlugin { public const string PluginId = "caspi.defencebot"; public const string Version = "0.1.3"; internal static ConfigEntry<int> Damage; internal static ConfigEntry<float> Range; internal static ConfigEntry<float> FireInterval; internal static ConfigEntry<float> FollowDistance; internal static ConfigEntry<int> BasePrice; private Harmony harmony; public static DefenceBotPlugin Instance { get; private set; } private void Awake() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown Instance = this; GameObject gameObject = ((Component)this).gameObject; ((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x3D); BasePrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "BasePrice", 0, new ConfigDescription("Base price before shop multipliers. 0 uses the native Feather Drone price range. Restart after changing.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000000), new object[0])); Damage = ((BaseUnityPlugin)this).Config.Bind<int>("Combat", "Damage", 25, new ConfigDescription("Enemy damage per shot. Host setting applies; native enemy resistance still applies.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 200), new object[0])); Range = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "Range", 12f, new ConfigDescription("Maximum targeting distance in game units. Host setting applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), new object[0])); FireInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "FireInterval", 0.8f, new ConfigDescription("Seconds between shots. Host setting applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 5f), new object[0])); FollowDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "FollowDistance", 2f, new ConfigDescription("Preferred distance beside and behind the followed player, in game units. Obstacles can temporarily change the distance. Host setting applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.2f, 4f), new object[0])); try { DefenceBotFactory.Validate(); harmony = new Harmony("caspi.defencebot"); harmony.PatchAll(typeof(DefenceBotPlugin).Assembly); if (Object.op_Implicit((Object)(object)StatsManager.instance)) { DefenceBotFactory.EnsureRegistered(StatsManager.instance); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Defence Bot 0.1.3 loaded. Deploy beside a player to follow and defend them."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Defence Bot could not initialize: " + ex)); if (harmony != null) { harmony.UnpatchSelf(); } ((Behaviour)this).enabled = false; } } internal static void LogWarning(string message) { if (Object.op_Implicit((Object)(object)Instance)) { ((BaseUnityPlugin)Instance).Logger.LogWarning((object)message); } } private void OnDestroy() { if (harmony != null) { harmony.UnpatchSelf(); } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } internal static class DefenceBotVisual { private sealed class Builder { private readonly List<Vector3> vertices = new List<Vector3>(); private readonly List<Vector2> uv = new List<Vector2>(); private readonly List<int> triangles = new List<int>(); internal void Triangle(Vector3 a, Vector3 b, Vector3 c) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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) int count = vertices.Count; vertices.Add(a); vertices.Add(b); vertices.Add(c); uv.Add(Vector2.zero); uv.Add(Vector2.right); uv.Add(Vector2.one); triangles.Add(count); triangles.Add(count + 1); triangles.Add(count + 2); } internal void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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) Triangle(a, b, c); Triangle(a, c, d); } internal Mesh Finish(string name) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown Mesh val = new Mesh(); ((Object)val).name = name; ((Object)val).hideFlags = (HideFlags)61; val.vertices = vertices.ToArray(); val.uv = uv.ToArray(); val.triangles = triangles.ToArray(); val.RecalculateNormals(); val.RecalculateBounds(); return val; } } internal const string RootName = "Defence Bot Visual"; private static Material shell; private static Material graphite; private static Material visor; private static Material cyan; private static Material paleCyan; private static Material orange; private static Mesh box; private static Mesh armour; private static Mesh tube; private static Mesh cylinder; internal static Transform Attach(GameObject bot) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_013b: 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_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_08a1: Unknown result type (might be due to invalid IL or missing references) //IL_08b5: Unknown result type (might be due to invalid IL or missing references) //IL_08da: Unknown result type (might be due to invalid IL or missing references) //IL_08ee: Unknown result type (might be due to invalid IL or missing references) //IL_0913: Unknown result type (might be due to invalid IL or missing references) //IL_0927: Unknown result type (might be due to invalid IL or missing references) //IL_094c: Unknown result type (might be due to invalid IL or missing references) //IL_0960: Unknown result type (might be due to invalid IL or missing references) //IL_0985: Unknown result type (might be due to invalid IL or missing references) //IL_0999: Unknown result type (might be due to invalid IL or missing references) //IL_09be: Unknown result type (might be due to invalid IL or missing references) //IL_09d2: Unknown result type (might be due to invalid IL or missing references) //IL_09e7: Unknown result type (might be due to invalid IL or missing references) //IL_09ee: Expected O, but got Unknown //IL_0a20: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03f5: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) //IL_044d: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0491: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04b9: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_0511: Unknown result type (might be due to invalid IL or missing references) //IL_0541: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_0569: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_05de: Unknown result type (might be due to invalid IL or missing references) //IL_05f2: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_0628: Unknown result type (might be due to invalid IL or missing references) //IL_063c: Unknown result type (might be due to invalid IL or missing references) //IL_0641: Unknown result type (might be due to invalid IL or missing references) //IL_0672: Unknown result type (might be due to invalid IL or missing references) //IL_0686: 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_06bc: 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_06d5: Unknown result type (might be due to invalid IL or missing references) //IL_0706: Unknown result type (might be due to invalid IL or missing references) //IL_071a: Unknown result type (might be due to invalid IL or missing references) //IL_071f: Unknown result type (might be due to invalid IL or missing references) //IL_0750: Unknown result type (might be due to invalid IL or missing references) //IL_0764: Unknown result type (might be due to invalid IL or missing references) //IL_0769: 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_07ae: Unknown result type (might be due to invalid IL or missing references) //IL_07f7: Unknown result type (might be due to invalid IL or missing references) //IL_080b: Unknown result type (might be due to invalid IL or missing references) //IL_084c: Unknown result type (might be due to invalid IL or missing references) //IL_0860: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)bot)) { throw new ArgumentNullException("bot"); } Transform val = bot.transform.Find("Drone"); if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("Native drone hierarchy is missing."); } Transform val2 = bot.transform.Find("Defence Bot Visual"); if (Object.op_Implicit((Object)(object)val2)) { return val2.Find("Defence Bot Turret/Muzzle"); } PrepareAssets(); GameObject val3 = new GameObject("Defence Bot Visual"); val3.SetActive(false); val3.layer = ((Component)val).gameObject.layer; val3.transform.SetParent(bot.transform, false); Transform transform = val3.transform; GameObject val4 = new GameObject("Defence Bot Turret"); val4.layer = val3.layer; val4.transform.SetParent(transform, false); val4.transform.localPosition = new Vector3(0f, -0.082f, 0.115f); Transform transform2 = val4.transform; Box(transform, "Graphite solid chassis", V(0f, 0f, -0.015f), V(0.36f, 0.32f, 0.34f), graphite, bevel: true); Box(transform, "White bevelled roof armour", V(0f, 0.149f, -0.027f), V(0.393f, 0.109f, 0.365f), shell, bevel: true); Box(transform, "White lower hull armour", V(0f, -0.165f, -0.019f), V(0.342f, 0.064f, 0.319f), shell, bevel: true); Box(transform, "Recessed black visor", V(0f, 0.056f, 0.163f), V(0.304f, 0.105f, 0.035f), visor, bevel: true); Box(transform, "Cyan scanning eye", V(0f, 0.055f, 0.184f), V(0.231f, 0.019f, 0.012f), cyan, bevel: false); Box(transform, "Bright eye centre", V(0f, 0.055f, 0.193f), V(0.044f, 0.033f, 0.012f), paleCyan, bevel: true); Box(transform, "Armoured brow", V(0f, 0.12f, 0.163f), V(0.324f, 0.042f, 0.058f), shell, bevel: true); Box(transform, "Orange chest plate", V(0f, -0.039f, 0.17f), V(0.096f, 0.06f, 0.022f), orange, bevel: true); Box(transform, "Chest lower seam", V(0f, -0.064f, 0.184f), V(0.059f, 0.007f, 0.006f), graphite, bevel: false); for (int i = -1; i <= 1; i += 2) { string text = ((i < 0) ? " left" : " right"); Box(transform, "White side armour" + text, V((float)i * 0.18f, 0.043f, -0.039f), V(0.063f, 0.23f, 0.275f), shell, bevel: true); Box(transform, "White cheek guard" + text, V((float)i * 0.148f, -0.014f, 0.161f), V(0.076f, 0.118f, 0.062f), shell, bevel: true); Box(transform, "Cheek inset" + text, V((float)i * 0.148f, 0.005f, 0.196f), V(0.033f, 0.01f, 0.006f), graphite, bevel: false); Box(transform, "Hover support" + text, V((float)i * 0.215f, -0.092f, -0.048f), V(0.086f, 0.068f, 0.106f), graphite, bevel: true); Round(transform, "Solid white hover pod" + text, V((float)i * 0.258f, -0.088f, -0.043f), V(0.077f, 0.077f, 0.126f), Quaternion.Euler(90f, 0f, 0f), shell, hollow: false); Round(transform, "Dark hover base" + text, V((float)i * 0.258f, -0.161f, -0.043f), V(0.071f, 0.071f, 0.03f), Quaternion.Euler(90f, 0f, 0f), graphite, hollow: false); Round(transform, "Cyan hover ring" + text, V((float)i * 0.258f, -0.182f, -0.043f), V(0.061f, 0.061f, 0.015f), Quaternion.Euler(90f, 0f, 0f), cyan, hollow: true); Round(transform, "Hover pod top cap" + text, V((float)i * 0.258f, -0.01f, -0.043f), V(0.036f, 0.036f, 0.037f), Quaternion.Euler(90f, 0f, 0f), graphite, hollow: false); Box(transform, "Orange side stripe" + text, V((float)i * 0.335f, -0.075f, -0.043f), V(0.008f, 0.049f, 0.029f), orange, bevel: false); Round(transform2, "Turret pivot" + text, V((float)i * 0.099f, 0f, 0.012f), V(0.041f, 0.041f, 0.064f), Quaternion.identity, graphite, hollow: false); Round(transform2, "Hollow gun barrel" + text, V((float)i * 0.099f, 0f, 0.105f), V(0.029f, 0.029f, 0.166f), Quaternion.identity, graphite, hollow: true); Round(transform2, "White barrel armour" + text, V((float)i * 0.099f, 0f, 0.094f), V(0.036f, 0.036f, 0.115f), Quaternion.identity, shell, hollow: true); Round(transform2, "Orange muzzle collar" + text, V((float)i * 0.099f, 0f, 0.162f), V(0.037f, 0.037f, 0.029f), Quaternion.identity, orange, hollow: true); Round(transform2, "Dark muzzle recess" + text, V((float)i * 0.099f, 0f, 0.176f), V(0.029f, 0.029f, 0.012f), Quaternion.identity, graphite, hollow: true); Round(transform2, "Cyan muzzle core" + text, V((float)i * 0.099f, 0f, 0.17f), V(0.015f, 0.015f, 0.005f), Quaternion.identity, cyan, hollow: false); Box(transform2, "Barrel mounting cheek" + text, V((float)i * 0.044f, 0.002f, 0.024f), V(0.047f, 0.078f, 0.057f), graphite, bevel: true); for (int j = 0; j < 3; j++) { Box(transform, "Side cooling slit" + text + j, V((float)i * 0.214f, 0.07f, -0.115f + (float)j * 0.036f), V(0.008f, 0.063f, 0.011f), visor, bevel: true); Box(transform, "Rear cooling slit" + text + j, V((float)i * 0.096f, 0.045f - (float)j * 0.029f, -0.189f), V(0.084f, 0.009f, 0.008f), visor, bevel: false); } } Box(transform, "Rear armour service door", V(0f, -0.074f, -0.192f), V(0.194f, 0.109f, 0.035f), shell, bevel: true); Box(transform, "Rear cyan status bar", V(0f, -0.075f, -0.213f), V(0.104f, 0.013f, 0.009f), cyan, bevel: false); Box(transform, "Rear service latch", V(0.062f, -0.113f, -0.213f), V(0.029f, 0.013f, 0.008f), graphite, bevel: false); Box(transform, "Antenna base", V(-0.136f, 0.193f, -0.097f), V(0.053f, 0.035f, 0.049f), graphite, bevel: true); Box(transform, "Short antenna", V(-0.136f, 0.236f, -0.097f), V(0.019f, 0.063f, 0.019f), graphite, bevel: false); Box(transform, "Cyan antenna lens", V(-0.136f, 0.278f, -0.097f), V(0.026f, 0.041f, 0.027f), cyan, bevel: true); GameObject val5 = new GameObject("Muzzle"); val5.layer = val3.layer; val5.transform.SetParent(transform2, false); val5.transform.localPosition = V(0f, 0f, 0.193f); HideNativeAppearance(bot); FitCollider(bot); val3.SetActive(true); return val5.transform; } internal static void HideNativeAppearance(GameObject bot) { Transform val = bot.transform.Find("Drone"); if (Object.op_Implicit((Object)(object)val)) { MeshRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { ((Renderer)val2).enabled = false; } } Transform val3 = bot.transform.Find("Drone Icon"); if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)((Component)val3).GetComponent<Renderer>())) { ((Component)val3).GetComponent<Renderer>().enabled = false; } } private static void FitCollider(GameObject bot) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) Transform val = bot.transform.Find("Valuable Box Collider"); BoxCollider val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<BoxCollider>() : null); if (!Object.op_Implicit((Object)(object)val2)) { throw new InvalidOperationException("Native bot pickup collider is missing."); } val.localPosition = V(0f, 0.022f, 0.042f); val.localRotation = Quaternion.identity; val.localScale = Vector3.one; val2.center = Vector3.zero; val2.size = V(0.672f, 0.445f, 0.548f); } private static Vector3 V(float x, float y, float z) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) return new Vector3(x, y, z); } private static void PrepareAssets() { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)shell) || !Object.op_Implicit((Object)(object)graphite) || !Object.op_Implicit((Object)(object)visor) || !Object.op_Implicit((Object)(object)cyan) || !Object.op_Implicit((Object)(object)paleCyan) || !Object.op_Implicit((Object)(object)orange) || !Object.op_Implicit((Object)(object)box) || !Object.op_Implicit((Object)(object)armour) || !Object.op_Implicit((Object)(object)tube) || !Object.op_Implicit((Object)(object)cylinder)) { Shader val = Shader.Find("Standard") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Sprites/Default"); if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("No robot material shader is available."); } shell = Material(val, "Robot ivory armour", new Color(0.83f, 0.85f, 0.81f), 0.14f, glow: false); graphite = Material(val, "Robot graphite chassis", new Color(0.064f, 0.075f, 0.078f), 0.52f, glow: false); visor = Material(val, "Robot black visor", new Color(0.009f, 0.019f, 0.023f), 0.15f, glow: false); cyan = Material(val, "Robot cyan light", new Color(0.025f, 0.78f, 0.94f), 0.1f, glow: true); paleCyan = Material(val, "Robot bright lens", new Color(0.48f, 0.96f, 1f), 0.1f, glow: true); orange = Material(val, "Robot orange paint", new Color(1f, 0.29f, 0.025f), 0.15f, glow: false); box = MakeBox(bevel: false); armour = MakeBox(bevel: true); tube = MakeRound(hollow: true); cylinder = MakeRound(hollow: false); } } private static Material Material(Shader shader, string name, Color color, float metal, bool glow) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(shader); ((Object)val).name = name; ((Object)val).hideFlags = (HideFlags)61; val.color = color; if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", metal); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", glow ? 0.38f : 0.22f); } if (glow && val.HasProperty("_EmissionColor")) { val.EnableKeyword("_EMISSION"); val.SetColor("_EmissionColor", color * 1.25f); } return val; } private static void Part(Transform parent, string name, Mesh mesh, Material material, Vector3 position, Vector3 scale, Quaternion rotation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.layer = ((Component)parent).gameObject.layer; val.transform.SetParent(parent, false); val.transform.localPosition = position; val.transform.localScale = scale; val.transform.localRotation = rotation; val.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer val2 = val.AddComponent<MeshRenderer>(); ((Renderer)val2).sharedMaterial = material; ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)val2).receiveShadows = true; } private static void Box(Transform parent, string name, Vector3 pos, Vector3 size, Material material, bool bevel) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Part(parent, name, bevel ? armour : box, material, pos, size, Quaternion.identity); } private static void Round(Transform parent, string name, Vector3 pos, Vector3 size, Quaternion rot, Material material, bool hollow) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Part(parent, name, hollow ? tube : cylinder, material, pos, size, rot); } private static Mesh MakeBox(bool bevel) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: 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_0117: Unknown result type (might be due to invalid IL or missing ref