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 ExtraDrones v1.0.0
BepInEx/plugins/DronesMod.dll
Decompiled 38 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Photon.Pun; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace DronesMod; [BepInPlugin("user.dronesmod", "Drones (Stun, Heal, Defense, Lucky)", "1.0.0")] public class Plugin : BaseUnityPlugin { private float dumpTimer; private bool dumped; private float regTimer; private float adminTimer; private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Drones mod loaded (Stun, Heal, Defense, Lucky). F8 = dump drone state"); DefenseGuard.Install(((BaseUnityPlugin)this).Logger); Registrar.Prefer = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SourceDroneName", "Torque", "Часть имени ванильного дрона, который копируется (Zero Gravity, Feather, Indestructible, Battery, Torque...). Пусто = авто.").Value; Registrar.PriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMin", 40000f, "Минимальная цена Stun Drone в магазине, $").Value; Registrar.PriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMax", 75000f, "Максимальная цена Stun Drone в магазине, $").Value; StunDroneLogic.BarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SecondsPerCharge", 10f, "Сколько секунд длится один заряд Stun Drone, пока он держит цель").Value; StunDroneLogic.StunCharges = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Charges", 6, "Сколько зарядов (полосок) у Stun Drone").Value; StunDroneLogic.ReleaseOnDetach = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReleaseOnDetach", false, "false = цель остаётся в стане, пока дрон не выключен и есть заряд, даже если луч отцепился; true = стан снимается сразу при отцеплении луча").Value; StunDroneLogic.StrictBeam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StrictBeam", true, "true = цель считается прицепленной, только если конец луча дрона реально лежит на ней (защита от залипшей ссылки на старую цель)").Value; Registrar.PriceScale = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceScale", 0f, "Множитель цены: 0 = авто (по ванильному предмету), 0.001 = значение в тысячах, 1 = цена как есть").Value; Registrar.ShopMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "ShopMultiplier", 0f, "Множитель магазина игры: 0 = авто (ShopManager.itemValueMultiplier, обычно 4). Цена делится на него, чтобы в магазине было PriceMin..PriceMax").Value; Registrar.HealPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMin", 25000f, "Минимальная цена Heal Drone в магазине, $").Value; Registrar.HealPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMax", 50000f, "Максимальная цена Heal Drone в магазине, $").Value; StunDroneLogic.HealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "HealAmount", 5, "Сколько HP лечит за один тик").Value; StunDroneLogic.HealInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "HealInterval", 1f, "Пауза между тиками лечения, секунд").Value; StunDroneLogic.HealCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "Charges", 10, "Сколько зарядов (полосок) у Heal Drone. Один тик лечения (HealAmount HP) = 1 заряд").Value; Registrar.DefPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMin", 30000f, "Минимальная цена Defense Drone в магазине, $").Value; Registrar.DefPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMax", 60000f, "Максимальная цена Defense Drone в магазине, $").Value; StunDroneLogic.DefCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Defense Drone", "Charges", 6, "Сколько зарядов (полосок) у Defense Drone").Value; StunDroneLogic.DefBarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "SecondsPerCharge", 10f, "Сколько секунд длится 1 заряд Defense Drone").Value; StunDroneLogic.DefDamageScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "DamageMultiplier", 0.25f, "Множитель входящего урона под защитой (0.25 = -75% урона)").Value; DefenseHudOverlay.ShieldOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetX", 8f, "Смещение иконки щита по X от правого края HealthMax (в единицах HUD)").Value; DefenseHudOverlay.ShieldOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetY", 0f, "Смещение иконки щита по Y от центра HealthMax (в единицах HUD), + вверх").Value; DefenseHudOverlay.ShieldScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldScale", 0.7f, "Масштаб иконки щита").Value; Registrar.LuckPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "PriceMin", 35000f, "Минимальная цена Lucky Drone в магазине, $").Value; Registrar.LuckPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "PriceMax", 70000f, "Максимальная цена Lucky Drone в магазине, $").Value; StunDroneLogic.LuckCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Lucky Drone", "Charges", 6, "Сколько зарядов (полосок) у Lucky Drone. Одна азартная игра = 1 заряд").Value; StunDroneLogic.LuckWinChance = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "WinChance", 0.5f, "Шанс выигрыша (0.5 = 50 на 50)").Value; StunDroneLogic.LuckGainMin = ((BaseUnityPlugin)this).Config.Bind<int>("Lucky Drone", "GainMin", 500, "Выигрыш: минимум, $").Value; StunDroneLogic.LuckGainMax = ((BaseUnityPlugin)this).Config.Bind<int>("Lucky Drone", "GainMax", 2000, "Выигрыш: максимум, $").Value; StunDroneLogic.LuckLossSmall = ((BaseUnityPlugin)this).Config.Bind<int>("Lucky Drone", "LossSmall", 200, "Проигрыш для дешёвых ценностей, $").Value; StunDroneLogic.LuckLossBig = ((BaseUnityPlugin)this).Config.Bind<int>("Lucky Drone", "LossBig", 500, "Проигрыш для дорогих ценностей, $").Value; StunDroneLogic.LuckBigThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "BigThreshold", 3000f, "Ценность, начиная с которой проигрыш = LossBig, $").Value; StunDroneLogic.LuckMinValue = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "MinValue", 100f, "Ценность никогда не опускается ниже этого значения, $").Value; StunDroneLogic.LuckOncePerValuable = ((BaseUnityPlugin)this).Config.Bind<bool>("Lucky Drone", "OncePerValuable", true, "true = на одной ценности можно сыграть только один раз").Value; StunDroneLogic.LuckWinSound = ((BaseUnityPlugin)this).Config.Bind<string>("Lucky Drone", "WinSound", "extraction point surplus done ding lvl4", "Имя звука (AudioClip) при выигрыше. Пусто = без звука").Value; StunDroneLogic.LuckLoseSound = ((BaseUnityPlugin)this).Config.Bind<string>("Lucky Drone", "LoseSound", "extraction point alarm", "Имя звука (AudioClip) при проигрыше. Пусто = без звука").Value; StunDroneLogic.LuckSoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Lucky Drone", "SoundVolume", 1f, "Громкость звуков Lucky Drone (0..1)").Value; } private void Update() { if (Input.GetKeyDown((KeyCode)289)) { StunDroneLogic[] array = Object.FindObjectsByType<StunDroneLogic>((FindObjectsSortMode)0); foreach (StunDroneLogic stunDroneLogic in array) { stunDroneLogic.DumpState(((BaseUnityPlugin)this).Logger); } } if (!Registrar.Done && Registrar.Tries < 300) { regTimer += Time.deltaTime; if (regTimer > 2f) { regTimer = 0f; Registrar.TryRegister(((BaseUnityPlugin)this).Logger); } } if (Registrar.AnyDone) { adminTimer += Time.deltaTime; if (adminTimer > 2f) { adminTimer = 0f; AdminSync.Run(((BaseUnityPlugin)this).Logger); } } if (!dumped) { dumpTimer += Time.deltaTime; if (dumpTimer > 10f) { dumped = true; Dumper.Run(((BaseUnityPlugin)this).Logger); } } } private void SpawnDrone(string itemName) { //IL_0111: 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_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_0103: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) StatsManager instance = StatsManager.instance; if ((Object)(object)instance == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"StatsManager not ready"); return; } Item val = null; foreach (Item value in instance.itemDictionary.Values) { if ((Object)(object)value != (Object)null && value.itemName == itemName) { val = value; break; } } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)(itemName + " is not registered yet (wait for the log line DONE)")); return; } Type type = Registrar.FindType("REPOLib.Modules.Items"); if (type == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"REPOLib not found"); return; } Camera main = Camera.main; Vector3 val2 = (((Object)(object)main != (Object)null) ? (((Component)main).transform.position + ((Component)main).transform.forward * 2f) : Vector3.up); object obj = type.GetMethod("SpawnItem").Invoke(null, new object[3] { val, val2, Quaternion.identity }); if (obj == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"SpawnItem returned null (are you the host? see REPOLib lines in the log)"); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)(itemName + " spawned")); } } } public class StunDroneLogic : MonoBehaviour { public enum Mode { Player, Monster } private enum Part { Skip, Main, Other } private const float Range = 6f; private const float MonsterStunSeconds = 1.5f; private const float NormalGravity = 30f; private const float PlayerStunSeconds = 3f; private const float AutoCooldown = 6f; private const BindingFlags RB = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; public Mode mode; public static int StunCharges = 6; public static int HealCharges = 10; public static int DefCharges = 6; public static float DefBarSeconds = 10f; public static float DefDamageScale = 0.25f; public static int LuckCharges = 6; public static int LuckGainMin = 500; public static int LuckGainMax = 2000; public static int LuckLossSmall = 200; public static int LuckLossBig = 500; public static float LuckWinChance = 0.5f; public static float LuckBigThreshold = 3000f; public static float LuckMinValue = 100f; public static bool LuckOncePerValuable = true; public static string LuckWinSound = "extraction point surplus done ding lvl4"; public static string LuckLoseSound = "extraction point alarm"; public static float LuckSoundVolume = 1f; public int charge = 1; private object target; private float stickUntil; private ItemAttributes[] attrs; private float gravTimer; private bool gravLogged; private static readonly Color OrangeC = new Color(1f, 0.5f, 0.05f, 1f); private static readonly Color GreenC = new Color(0.15f, 1f, 0.3f, 1f); private static readonly Color DarkBlueC = new Color(0.08f, 0.28f, 1f, 1f); private static readonly Color GoldC = new Color(1f, 0.82f, 0.1f, 1f); private bool batLogged; private bool torqueLogged; private bool scriptsDone; private Texture2D iconTex; private bool iconPending; private int bornFrame; private bool iconLogged; private static bool logged; private float nextAuto; private float reapplyTimer; private bool targetingDone; private ItemDrone droneComp; private bool wasAttached; private bool loggedScan; private float nextDiag; private float holdTimer; private object attachedObj; public static bool StrictBeam = true; public static bool ReleaseOnDetach = false; public static float BarSeconds = 3f; private float drainTimer; private object stunned; private float attachStart; private bool capped; private object relTarget; private float relUntil; private float relNext; private static bool stunLogged; private float nextBeamLog; private HashSet<Renderer> batRend = new HashSet<Renderer>(); private List<Renderer> beamList = new List<Renderer>(); private Dictionary<Renderer, int[]> beamProps = new Dictionary<Renderer, int[]>(); private float nextBeamFind; private bool fieldColorLogged; private Component batteryComp; private float nextBatFind; private bool batteryLogged; private bool uiDumped; private float lifeVal = -1f; private int lastCharge; private float nextBatDump; private int dumpedCharge = -1; private static readonly HashSet<int> luckRolled = new HashSet<int>(); private object luckPrev; private static readonly Dictionary<string, AudioClip> luckClips = new Dictionary<string, AudioClip>(); public static int HealAmount = 5; public static float HealInterval = 1f; private float nextHeal; private bool healWarned; private Component tumbleCache; private PlayerAvatar cachedFor; private bool tumbleWarned; private bool stunWarned; private bool stunWarned2; private bool stunOk; private static HashSet<string> noStunLogged = new HashSet<string>(); private int lastDefHp = -1; private PlayerAvatar lastDefPlayer; private int Cap => Math.Max(1, Luck ? LuckCharges : (Defense ? DefCharges : (Heal ? HealCharges : StunCharges))); private string DisplayName => Luck ? "Lucky Drone" : (Defense ? "Defense Drone" : (Heal ? "Heal Drone" : "Stun Drone")); private bool Heal => this is HealDroneLogic; private bool Defense => this is DefenseDroneLogic; private bool Luck => this is LuckDroneLogic; private Color Orange => Luck ? GoldC : (Defense ? DarkBlueC : (Heal ? GreenC : OrangeC)); private void Awake() { charge = Cap; CollectBatteryRenderers(); MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery") { SetNum(val, "batteryBars", Cap); } } mode = ((!Heal && !Defense && !Luck && !(Random.value < 0.5f)) ? Mode.Monster : Mode.Player); Retexture(); ApplyIcon(); bornFrame = Time.frameCount; ApplyTargeting(); attrs = ((Component)this).GetComponentsInChildren<ItemAttributes>(true); ForceName(); Debug.Log((object)string.Concat("[StunDrone] spawned, mode=", mode, ", name=", DumpName())); } private void ForceName() { if (attrs == null) { return; } ItemAttributes[] array = attrs; foreach (ItemAttributes val in array) { if (!((Object)(object)val == (Object)null)) { SetStr(val, "itemName", DisplayName); SetStr(val, "instanceName", DisplayName); SetStr(val, "cachedItemName", DisplayName); } } } private string DumpName() { if (attrs == null || attrs.Length == 0) { return "<no ItemAttributes>"; } ItemAttributes o = attrs[0]; return GetStr(o, "itemName") + " / " + GetStr(o, "cachedItemName"); } private static void SetStr(object o, string name, string v) { FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(string)) { field.SetValue(o, v); } } private static string GetStr(object o, string name) { FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return (field != null) ? (field.GetValue(o) as string) : "?"; } private void ApplyGravity() { MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } Type type = ((object)val).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!(fieldInfo.FieldType != typeof(float)) && !(fieldInfo.Name.ToLower() != "customgravity")) { float num = (float)fieldInfo.GetValue(val); if (!gravLogged) { Debug.Log((object)("[StunDrone] " + type.Name + "." + fieldInfo.Name + ": " + num + " -> " + 30f)); } if (num != 30f) { fieldInfo.SetValue(val, 30f); } } } type = type.BaseType; } } gravLogged = true; } private void ApplyColors() { //IL_00af: 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_00e6: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: 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) Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!(val is ParticleSystemRenderer) && Classify(((Component)val).transform) == Part.Other && !IsBatteryRenderer(val)) { Material material = val.material; if (material.HasProperty("_EmissionColor")) { material.SetColor("_EmissionColor", Orange); } } } Light[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Light>(true); foreach (Light val2 in componentsInChildren2) { val2.color = Orange; } LineRenderer[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<LineRenderer>(true); foreach (LineRenderer val3 in componentsInChildren3) { val3.startColor = Orange; val3.endColor = Orange; } ParticleSystem[] componentsInChildren4 = ((Component)this).GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val4 in componentsInChildren4) { MainModule main = val4.main; ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Orange); } } private void ApplyBatteryColor() { //IL_013c: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery members: "); MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null || ((object)val).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Type type = ((object)val).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!batLogged) { object value = null; try { value = fieldInfo.GetValue(val); } catch { } stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name) .Append('=') .Append(value) .Append("; "); } if (fieldInfo.FieldType == typeof(Color) && (fieldInfo.Name.Equals("batteryColor", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMain", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMedium", StringComparison.OrdinalIgnoreCase))) { fieldInfo.SetValue(val, Orange); } } type = type.BaseType; } } if (!batLogged) { batLogged = true; Debug.Log((object)stringBuilder.ToString()); } } private void RemoveTorque() { //IL_016f: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[StunDrone] torque members: "); MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } Type type = ((object)val).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { string text = fieldInfo.Name.ToLower(); if (text.Contains("torque") || text.Contains("spin")) { object value = null; try { value = fieldInfo.GetValue(val); } catch { } if (!torqueLogged) { stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name) .Append('=') .Append(value) .Append("; "); } if (fieldInfo.FieldType == typeof(float)) { fieldInfo.SetValue(val, 0f); } else if (fieldInfo.FieldType == typeof(bool)) { fieldInfo.SetValue(val, false); } else if (fieldInfo.FieldType == typeof(Vector3)) { fieldInfo.SetValue(val, Vector3.zero); } } } type = type.BaseType; } } if (!torqueLogged) { torqueLogged = true; Debug.Log((object)stringBuilder.ToString()); } } private void RemoveTorqueScripts() { if (scriptsDone) { return; } scriptsDone = true; StringBuilder stringBuilder = new StringBuilder("[StunDrone] scripts on drone: "); MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } string name = ((object)val).GetType().Name; stringBuilder.Append(((Object)((Component)val).gameObject).name).Append(':').Append(name) .Append("; "); if (!((Object)(object)val == (Object)(object)this) && !(name == "ItemDrone")) { string text = name.ToLower(); if (text.Contains("torque") || text.Contains("spin")) { Debug.Log((object)("[StunDrone] removing script " + name + " on " + ((Object)((Component)val).gameObject).name)); Object.Destroy((Object)(object)val); } } } Debug.Log((object)stringBuilder.ToString()); } private void LateUpdate() { ForceName(); SyncBattery(); TintBeams(); if (Time.frameCount > bornFrame + 5) { RemoveTorqueScripts(); } if (Time.time > gravTimer) { gravTimer = Time.time + 0.5f; ApplyGravity(); ApplyColors(); ApplyBatteryColor(); ApplyDroneFieldColors(); RemoveTorque(); if ((Object)(object)iconTex != (Object)null && Time.frameCount > bornFrame + 3) { ApplyIconMaterial(); } } } private void ApplyTargeting() { ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true); if (!((Object)(object)componentInChildren == (Object)null)) { if (Luck) { SetBool(componentInChildren, "targetValuables", v: true); SetBool(componentInChildren, "targetNonValuables", v: false); SetBool(componentInChildren, "targetPlayers", v: false); SetBool(componentInChildren, "targetEnemies", v: false); } else { SetBool(componentInChildren, "targetValuables", v: false); SetBool(componentInChildren, "targetNonValuables", v: false); SetBool(componentInChildren, "targetPlayers", v: true); SetBool(componentInChildren, "targetEnemies", !Heal && !Defense); } } } private static void SetBool(object o, string name, bool v) { FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { field.SetValue(o, v); } else { Debug.LogWarning((object)("[StunDrone] field " + name + " not found")); } } private void ApplyIcon() { iconTex = (Luck ? LoadEmbedded("luck_icon.png") : LoadEmbedded(Defense ? "def_icon.png" : (Heal ? "heal_icon.png" : "icon.png"))); Debug.Log((object)("[StunDrone] icon.png embedded in DLL: " + ((Object)(object)iconTex != (Object)null) + (((Object)(object)iconTex == (Object)null) ? " (put tex\\3.png next to build.bat and rebuild)" : ""))); if ((Object)(object)iconTex == (Object)null) { return; } ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true); if ((Object)(object)componentInChildren != (Object)null) { FieldInfo field = typeof(ItemDrone).GetField("droneIcon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { field.SetValue(componentInChildren, iconTex); } else { Debug.LogWarning((object)"[StunDrone] field droneIcon not found"); } } else { Debug.LogWarning((object)"[StunDrone] ItemDrone not found on prefab"); } iconPending = true; bornFrame = Time.frameCount; } private void ApplyIconMaterial() { //IL_0107: 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_0155: Unknown result type (might be due to invalid IL or missing references) int num = 0; Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { bool flag = false; Transform val2 = ((Component)val).transform; while ((Object)(object)val2 != (Object)null) { if (((Object)val2).name.Replace('_', ' ').Trim().StartsWith("Drone Icon")) { flag = true; break; } val2 = val2.parent; } if (flag) { Material material = val.material; material.EnableKeyword("_EMISSION"); material.SetTexture("_EmissionMap", (Texture)(object)iconTex); if (material.HasProperty("_MainTex")) { material.SetTexture("_MainTex", (Texture)(object)iconTex); } if (material.HasProperty("_BaseMap")) { material.SetTexture("_BaseMap", (Texture)(object)iconTex); } if (material.HasProperty("_EmissionColor")) { material.SetColor("_EmissionColor", Color.white); } if (material.HasProperty("_Color")) { material.SetColor("_Color", Color.white); } if (material.HasProperty("_BaseColor")) { material.SetColor("_BaseColor", Color.white); } num++; } } if (!iconLogged) { iconLogged = true; Debug.Log((object)("[StunDrone] icon applied to " + num + " renderer(s) named 'Drone Icon'")); } } private void Retexture() { //IL_00e1: 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_00a0: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) Texture2D val = (Luck ? (LoadEmbedded("luck_albedo.png") ?? Procedural(new Color(0.95f, 0.75f, 0.1f))) : ((Defense ? LoadEmbedded("def_albedo.png") : (Heal ? LoadEmbedded("heal_albedo.png") : null)) ?? LoadEmbedded("albedo.png") ?? Procedural(Defense ? new Color(0.08f, 0.25f, 0.95f) : (Heal ? new Color(0.2f, 0.8f, 0.3f) : ((mode == Mode.Player) ? new Color(0.9f, 0.55f, 0.1f) : new Color(0.1f, 0.6f, 0.8f)))))); Texture2D val2 = (Luck ? LoadEmbedded("luck_emission.png") : ((Defense ? LoadEmbedded("def_emission.png") : (Heal ? LoadEmbedded("heal_emission.png") : null)) ?? LoadEmbedded("emission.png"))); Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val3 in componentsInChildren) { if (IsBatteryRenderer(val3)) { continue; } Part part = Classify(((Component)val3).transform); if (!logged) { Debug.Log((object)("[StunDrone] renderer '" + ((Object)val3).name + "' -> " + part)); } if (part == Part.Skip) { continue; } Material material = val3.material; if (material.HasProperty("_MainTex")) { material.SetTexture("_MainTex", (Texture)(object)val); } if (material.HasProperty("_BaseMap")) { material.SetTexture("_BaseMap", (Texture)(object)val); } if (part == Part.Main) { if (material.HasProperty("_EmissionMap")) { material.SetTexture("_EmissionMap", (Texture)null); } material.DisableKeyword("_EMISSION"); } else if ((Object)(object)val2 != (Object)null && material.HasProperty("_EmissionMap")) { material.EnableKeyword("_EMISSION"); material.SetTexture("_EmissionMap", (Texture)(object)val2); material.SetColor("_EmissionColor", Color.white); } } logged = true; } private static Part Classify(Transform t) { Transform val = t; while ((Object)(object)val != (Object)null) { string text = ((Object)val).name.Replace('_', ' ').Trim(); if (text.StartsWith("Drone Icon")) { return Part.Skip; } if (text.Contains("Drone Triangle") || text.Contains("Drone Pyramid")) { return Part.Other; } if (text == "Drone") { return Part.Main; } val = val.parent; } return Part.Skip; } private static Texture2D LoadEmbedded(string name) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); if (stream == null) { return null; } MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, memoryStream.ToArray()); return val; } private static Texture2D Procedural(Color c) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_002e: 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_0027: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { val.SetPixel(j, i, ((j / 8 + i / 8) % 2 == 0) ? c : (c * 0.6f)); } } val.Apply(); return val; } private void Update() { if (!targetingDone && Time.frameCount > bornFrame + 2) { targetingDone = true; ApplyTargeting(); } if (iconPending && Time.frameCount >= bornFrame + 3) { iconPending = false; ApplyIconMaterial(); } KeepReleasing(); if ((Object)(object)droneComp == (Object)null) { droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true); } if (Luck) { LuckTick(); return; } object obj = ((charge > 0) ? DetectAttached() : null); if (stunned != null && !ReleaseOnDetach && !Heal && !Defense) { object obj2 = stunned; Component val = (Component)((obj2 is Component) ? obj2 : null); obj = (((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null && charge > 0 && ToggleOn()) ? stunned : null); } if (capped && obj == null) { capped = false; } if (capped) { obj = null; } if (stunned != null && !object.ReferenceEquals(stunned, obj)) { Release(stunned); stunned = null; } if (obj != null && stunned == null) { if (object.ReferenceEquals(relTarget, obj)) { relTarget = null; } stunned = obj; attachStart = Time.time; holdTimer = 0f; drainTimer = 0f; Debug.Log((object)string.Concat("[StunDrone] attached to ", obj, ", charge=", charge)); } attachedObj = stunned; if (stunned == null) { return; } float num = (Defense ? DefBarSeconds : BarSeconds); if (!Heal) { drainTimer += Time.deltaTime; } if (!Heal && drainTimer >= num) { drainTimer = 0f; charge--; Debug.Log((object)("[StunDrone] charge=" + charge)); if (charge <= 0) { Debug.Log((object)("[StunDrone] charge empty, releasing " + stunned)); Release(stunned); stunned = null; attachedObj = null; return; } } if (Heal) { HealTick(); return; } if (Defense) { object obj3 = stunned; PlayerAvatar val2 = (PlayerAvatar)((obj3 is PlayerAvatar) ? obj3 : null); if ((Object)(object)val2 != (Object)null) { DefenseTick(val2); } return; } object obj4 = stunned; PlayerAvatar val3 = (PlayerAvatar)((obj4 is PlayerAvatar) ? obj4 : null); if ((Object)(object)val3 != (Object)null) { StunPlayer(val3); return; } holdTimer -= Time.deltaTime; if (!(holdTimer > 0f)) { holdTimer = 0.2f; object obj5 = stunned; Enemy val4 = (Enemy)((obj5 is Enemy) ? obj5 : null); if ((Object)(object)val4 != (Object)null) { StunEnemy(val4); } } } public void DumpState(ManualLogSource log) { //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat("==== ", DateTime.Now.ToString("HH:mm:ss"), " mode=", mode, " charge=", charge, " stunned=", stunned, " toggleOn=", ToggleOn())); if ((Object)(object)droneComp == (Object)null) { droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true); } if ((Object)(object)droneComp != (Object)null) { Type type = ((object)droneComp).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { object obj = null; try { obj = fieldInfo.GetValue(droneComp); } catch { } stringBuilder.AppendLine(" ItemDrone." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString())); } type = type.BaseType; } } LineRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<LineRenderer>(true); foreach (LineRenderer val in componentsInChildren) { stringBuilder.AppendLine(" LineRenderer " + ((Object)val).name + " enabled=" + ((Renderer)val).enabled + " active=" + ((Component)val).gameObject.activeInHierarchy + " points=" + val.positionCount + ((val.positionCount >= 2) ? string.Concat(" p0=", val.GetPosition(0), " pN=", val.GetPosition(val.positionCount - 1), " worldSpace=", val.useWorldSpace) : "")); } MonoBehaviour[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val2 in componentsInChildren2) { if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)this || (Object)(object)val2 == (Object)(object)droneComp) { continue; } string name = ((object)val2).GetType().Name; if (name.IndexOf("Line", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Magnet", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Drone", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Type type = ((object)val2).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { object obj = null; try { obj = fieldInfo.GetValue(val2); } catch { } stringBuilder.AppendLine(" " + name + "." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString())); } type = type.BaseType; } } try { string text = Path.Combine(Paths.BepInExRootPath, "StunDrone_state.txt"); File.AppendAllText(text, stringBuilder.ToString()); log.LogInfo((object)("State dumped: " + text)); } catch (Exception ex) { log.LogError((object)("State dump failed: " + ex.Message)); } } private void KeepReleasing() { if (relTarget == null) { return; } if (Time.time > relUntil) { relTarget = null; } else { if (Time.time < relNext) { return; } relNext = Time.time + 0.2f; object obj = relTarget; PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null); if (!((Object)(object)val == (Object)null)) { Component val2 = FindTumble(val); if ((Object)(object)val2 != (Object)null) { CallMethod(val2, "TumbleOverrideTime", 0f); CallMethod(val2, "TumbleRequest", false, false); } } } } private void OnDisable() { if (stunned != null) { Release(stunned); stunned = null; } } private void OnDestroy() { if (stunned != null) { Release(stunned); stunned = null; } } private void Release(object target) { if (Heal || Luck) { return; } if (Defense) { ClearDefense(target); return; } relTarget = target; relUntil = Time.time + 1.2f; relNext = Time.time + 0.2f; try { PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null); if ((Object)(object)val != (Object)null) { Component val2 = FindTumble(val); if ((Object)(object)val2 != (Object)null) { CallMethod(val2, "TumbleOverrideTime", 0f); CallMethod(val2, "TumbleRequest", false, false); } Debug.Log((object)"[StunDrone] released player"); } Enemy val3 = (Enemy)((target is Enemy) ? target : null); if (!((Object)(object)val3 != (Object)null)) { return; } Component val4 = FindStun((Component)(object)val3); if ((Object)(object)val4 != (Object)null) { Type type = ((object)val4).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo field = type.GetField("stunTimer", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(float)) { field.SetValue(val4, 0.05f); } type = type.BaseType; } } MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)val3)).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val5 in componentsInChildren) { if ((Object)(object)val5 == (Object)null) { continue; } Type type = ((object)val5).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { field.SetValue(val5, false); } PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(bool) && property.CanWrite) { try { property.SetValue(val5, false, null); } catch { } } type = type.BaseType; } } Debug.Log((object)"[StunDrone] released enemy"); } catch (Exception ex) { Debug.LogWarning((object)("[StunDrone] Release: " + ex.Message)); } } private object DetectAttached() { object obj = null; if (!ToggleOn()) { return null; } object obj2 = stunned; PlayerAvatar val = (PlayerAvatar)((obj2 is PlayerAvatar) ? obj2 : null); if ((Object)(object)val != (Object)null && IsHolder(val)) { return val; } if ((Object)(object)droneComp != (Object)null) { Type type = ((object)droneComp).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { object value; try { value = fieldInfo.GetValue(droneComp); } catch { continue; } Object val2 = (Object)((value is Object) ? value : null); IList list = value as IList; if (val2 == (Object)null && list != null) { foreach (object item in list) { val2 = (Object)((item is Object) ? item : null); if (val2 != (Object)null) { break; } } } if (val2 == (Object)null || val2 == (Object)(object)droneComp || val2 == (Object)(object)((Component)this).gameObject) { continue; } Component val3 = (Component)(object)((val2 is Component) ? val2 : null); GameObject val4 = (GameObject)(object)((val2 is GameObject) ? val2 : null); if ((Object)(object)val3 == (Object)null && (Object)(object)val4 != (Object)null) { val3 = (Component)(object)val4.transform; } if ((Object)(object)val3 == (Object)null) { continue; } PlayerAvatar componentInParent = val3.GetComponentInParent<PlayerAvatar>(); if ((Object)(object)componentInParent == (Object)null) { Component componentInParent2 = val3.GetComponentInParent(Registrar.FindType("PlayerTumble") ?? typeof(Transform)); if ((Object)(object)componentInParent2 != (Object)null) { componentInParent = componentInParent2.GetComponentInParent<PlayerAvatar>(); } } if ((Object)(object)componentInParent != (Object)null && !IsHolder(componentInParent)) { obj = componentInParent; if (!loggedScan) { loggedScan = true; Debug.Log((object)("[StunDrone] target field (player): ItemDrone." + fieldInfo.Name)); } break; } Enemy val5 = ((Heal || Defense) ? null : EnemyFrom(val3)); if (!((Object)(object)val5 != (Object)null)) { continue; } obj = val5; if (!loggedScan) { loggedScan = true; Debug.Log((object)("[StunDrone] target field (enemy): ItemDrone." + fieldInfo.Name)); } break; } if (obj != null) { break; } type = type.BaseType; } } if (obj != null && StrictBeam && !BeamOnTarget(obj)) { if (Time.time > nextBeamLog) { nextBeamLog = Time.time + 2f; Debug.Log((object)string.Concat("[StunDrone] ItemDrone still references ", obj, " but the beam is not on it -> not attached")); } obj = null; } if (obj != null) { return obj; } if ((Object)(object)droneComp != (Object)null && Time.time > nextDiag && LineOn() && ToggleOn()) { nextDiag = Time.time + 3f; StringBuilder stringBuilder = new StringBuilder("[StunDrone] no target found; ItemDrone fields: "); Type type = ((object)droneComp).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { object value = null; try { value = fieldInfo.GetValue(droneComp); } catch { } stringBuilder.Append(fieldInfo.Name).Append('=').Append((value == null) ? "null" : value.ToString()) .Append("; "); } type = type.BaseType; } Debug.Log((object)stringBuilder.ToString()); } return null; } private bool ToggleOn() { Type type = Registrar.FindType("ItemToggle"); if (type == null) { return true; } Component val = ((Component)this).GetComponentInChildren(type, true); if ((Object)(object)val == (Object)null) { val = ((Component)this).GetComponentInParent(type); } if ((Object)(object)val == (Object)null) { return true; } Type type2 = ((object)val).GetType(); while (type2 != null) { FieldInfo field = type2.GetField("toggleState", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { return (bool)field.GetValue(val); } type2 = type2.BaseType; } return true; } private bool IsHolder(PlayerAvatar p) { try { Type type = Registrar.FindType("PhysGrabObject"); if (type == null) { return false; } Component val = ((Component)this).GetComponentInParent(type); if ((Object)(object)val == (Object)null) { val = ((Component)this).GetComponentInChildren(type, true); } if ((Object)(object)val == (Object)null) { return false; } FieldInfo field = ((object)val).GetType().GetField("playerGrabbing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); IList list = ((field != null) ? (field.GetValue(val) as IList) : null); if (list == null) { return false; } foreach (object item in list) { if (item == null) { continue; } Component val2 = (Component)((item is Component) ? item : null); if ((Object)(object)val2 == (Object)null) { continue; } PlayerAvatar val3 = val2.GetComponentInParent<PlayerAvatar>(); if ((Object)(object)val3 == (Object)null) { FieldInfo field2 = item.GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 != null) { object? value = field2.GetValue(item); val3 = (PlayerAvatar)((value is PlayerAvatar) ? value : null); } } if (!((Object)(object)val3 == (Object)(object)p)) { continue; } return true; } } catch { } return false; } private static Transform EnemyRoot(Component e) { Type type = Registrar.FindType("EnemyParent"); if (type != null) { Component componentInParent = e.GetComponentInParent(type); if ((Object)(object)componentInParent != (Object)null) { return componentInParent.transform; } } Transform val = null; Transform val2 = e.transform; while ((Object)(object)val2 != (Object)null) { if (((Object)val2).name.StartsWith("Enemy")) { val = val2; } val2 = val2.parent; } return ((Object)(object)val != (Object)null) ? val : e.transform.root; } private static Transform TargetRoot(Component c) { return (c is Enemy) ? EnemyRoot(c) : c.transform.root; } private static Component FindStun(Component e) { Component val = null; StringBuilder stringBuilder = (stunLogged ? null : new StringBuilder("[StunDrone] enemy state components: ")); MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot(e)).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { string name = ((object)val2).GetType().Name; if (stringBuilder != null && name.StartsWith("EnemyState")) { stringBuilder.Append(name).Append("; "); } if ((Object)(object)val == (Object)null && name.StartsWith("EnemyState") && name.ToLower().Contains("stun")) { val = (Component)(object)val2; } } } if (stringBuilder != null) { stunLogged = true; Debug.Log((object)(stringBuilder.ToString() + " -> stun: " + (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "NOT FOUND"))); } return val; } private static Enemy EnemyFrom(Component c) { Enemy componentInParent = c.GetComponentInParent<Enemy>(); if ((Object)(object)componentInParent != (Object)null) { return componentInParent; } Type type = Registrar.FindType("EnemyParent"); if (type != null) { Component componentInParent2 = c.GetComponentInParent(type); if ((Object)(object)componentInParent2 != (Object)null) { componentInParent = componentInParent2.GetComponentInChildren<Enemy>(true); if ((Object)(object)componentInParent != (Object)null) { return componentInParent; } } } Transform val = c.transform; while ((Object)(object)val != (Object)null) { MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>(); foreach (MonoBehaviour val2 in components) { if ((Object)(object)val2 == (Object)null) { continue; } Type type2 = ((object)val2).GetType(); while (type2 != null && type2 != typeof(MonoBehaviour)) { FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType == typeof(Enemy)) { object? value = fieldInfo.GetValue(val2); Enemy val3 = (Enemy)((value is Enemy) ? value : null); if ((Object)(object)val3 != (Object)null) { return val3; } } } type2 = type2.BaseType; } } val = val.parent; } return null; } private bool BeamOnTarget(object target) { //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_0039: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: 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_013d: 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_0170: 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_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) Component val = (Component)((target is Component) ? target : null); if ((Object)(object)val == (Object)null) { return false; } bool flag = false; Bounds bounds = default(Bounds); ((Bounds)(ref bounds))..ctor(val.transform.position, Vector3.one * 0.5f); bool flag2 = true; Renderer[] componentsInChildren = ((Component)TargetRoot(val)).GetComponentsInChildren<Renderer>(false); foreach (Renderer val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null) && !(val2 is ParticleSystemRenderer) && !(val2 is LineRenderer)) { if (flag2) { bounds = val2.bounds; flag2 = false; } else { ((Bounds)(ref bounds)).Encapsulate(val2.bounds); } } } LineRenderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<LineRenderer>(false); foreach (LineRenderer val3 in componentsInChildren2) { if (!((Object)(object)val3 == (Object)null) && ((Renderer)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && val3.positionCount >= 2) { flag = true; Vector3 val4 = val3.GetPosition(0); Vector3 val5 = val3.GetPosition(val3.positionCount - 1); if (!val3.useWorldSpace) { val4 = ((Component)val3).transform.TransformPoint(val4); val5 = ((Component)val3).transform.TransformPoint(val5); } if (!(Vector3.Distance(val4, val5) < 0.3f) && (((Bounds)(ref bounds)).SqrDistance(val4) < 4f || ((Bounds)(ref bounds)).SqrDistance(val5) < 4f)) { return true; } } } if (!flag && Time.time > nextBeamLog) { nextBeamLog = Time.time + 2f; Debug.Log((object)"[StunDrone] no active LineRenderer on drone"); } return false; } private bool LineOn() { Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(false); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "Line" && ((Component)val).gameObject.activeInHierarchy) { return true; } } return false; } private static bool BoolMember(object o, string name) { Type type = o.GetType(); while (type != null) { FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { return (bool)field.GetValue(o); } PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(bool) && property.CanRead && property.GetIndexParameters().Length == 0) { try { return (bool)property.GetValue(o, null); } catch { return false; } } type = type.BaseType; } return false; } private static Component FindComp(Component c, string typeName) { Type type = Registrar.FindType(typeName); if (type == null) { return null; } Component val = c.GetComponentInChildren(type, true); if ((Object)(object)val == (Object)null) { val = c.GetComponentInParent(type); } if ((Object)(object)val == (Object)null) { val = ((Component)c.transform.root).GetComponentInChildren(type, true); } return val; } private static bool CallMethod(object o, string name, params object[] args) { Type type = o.GetType(); while (type != null) { MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != name) { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length >= args.Length) { object[] array = new object[parameters.Length]; for (int j = 0; j < parameters.Length; j++) { array[j] = ((j < args.Length) ? args[j] : (parameters[j].IsOptional ? parameters[j].DefaultValue : null)); } try { methodInfo.Invoke(o, array); return true; } catch (Exception ex) { Debug.LogWarning((object)("[StunDrone] " + name + " threw: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message))); } } } type = type.BaseType; } return false; } private static Component FindTumble(PlayerAvatar p) { Type type = ((object)p).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType.Name == "PlayerTumble") { object? value = fieldInfo.GetValue(p); Component val = (Component)((value is Component) ? value : null); if ((Object)(object)val != (Object)null) { return val; } } } PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo propertyInfo in properties) { if (!(propertyInfo.PropertyType.Name == "PlayerTumble") || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0) { continue; } try { object? value2 = propertyInfo.GetValue(p, null); Component val = (Component)((value2 is Component) ? value2 : null); if ((Object)(object)val != (Object)null) { return val; } } catch { } } type = type.BaseType; } Component val2 = FindComp((Component)(object)p, "PlayerTumble"); if ((Object)(object)val2 != (Object)null) { return val2; } Type type2 = Registrar.FindType("PlayerTumble"); if (type2 == null) { return null; } Object[] array = Object.FindObjectsByType(type2, (FindObjectsSortMode)0); foreach (Object val3 in array) { Component val4 = (Component)(object)((val3 is Component) ? val3 : null); if ((Object)(object)val4 == (Object)null) { continue; } Type type3 = ((object)val4).GetType(); while (type3 != null && type3 != typeof(MonoBehaviour)) { FieldInfo[] fields = type3.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo2 in fields) { if (fieldInfo2.FieldType == typeof(PlayerAvatar) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)p) { return val4; } } type3 = type3.BaseType; } } return null; } private PlayerAvatar FindNearestPlayer() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) PlayerAvatar result = null; float num = 6f; PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0); foreach (PlayerAvatar val in array) { if (!BoolMember(val, "isDisabled") && !BoolMember(val, "deadSet") && !((Object)(object)FindTumble(val) == (Object)null)) { float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position); if (num2 < num) { num = num2; result = val; } } } return result; } private Enemy FindNearestEnemy(bool skipStunned) { //IL_003c: 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) Enemy result = null; float num = 6f; Enemy[] array = Object.FindObjectsByType<Enemy>((FindObjectsSortMode)0); foreach (Enemy val in array) { if (!skipStunned || !val.IsStunned()) { float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position); if (num2 < num) { num = num2; result = val; } } } return result; } private static bool IsDronePartName(string n) { n = n.Replace('_', ' ').Trim(); return n == "Drone" || n.StartsWith("Drone Triangle") || n.StartsWith("Drone Pyramid") || n.StartsWith("Drone Icon"); } private void AddBatteryRefs(object v) { if (v == null) { return; } if (v is IEnumerable enumerable && !(v is string) && !(v is Object)) { foreach (object item2 in enumerable) { AddBatteryRefs(item2); } return; } Object val = (Object)((v is Object) ? v : null); if (val == (Object)null) { return; } Transform val2 = null; Renderer val3 = (Renderer)(object)((val is Renderer) ? val : null); if ((Object)(object)val3 != (Object)null) { batRend.Add(val3); return; } Component val4 = (Component)(object)((val is Component) ? val : null); if ((Object)(object)val4 != (Object)null) { val2 = val4.transform; } GameObject val5 = (GameObject)(object)((val is GameObject) ? val : null); if ((Object)(object)val5 != (Object)null) { val2 = val5.transform; } if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)((Component)this).transform) && !((Component)this).transform.IsChildOf(val2) && !IsDronePartName(((Object)val2).name)) { Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true); foreach (Renderer item in componentsInChildren) { batRend.Add(item); } } } private void CollectBatteryRenderers() { MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this) { continue; } string name = ((object)val).GetType().Name; if (name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0) { continue; } if (name.IndexOf("Visual", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)((Component)val).transform != (Object)(object)((Component)this).transform && !IsDronePartName(((Object)((Component)val).transform).name)) { Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true); foreach (Renderer item in componentsInChildren2) { batRend.Add(item); } } Type type = ((object)val).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!fieldInfo.FieldType.IsPrimitive && !(fieldInfo.FieldType == typeof(string))) { object v = null; try { v = fieldInfo.GetValue(val); } catch { } AddBatteryRefs(v); } } type = type.BaseType; } } Debug.Log((object)("[StunDrone] battery renderers excluded from retexture: " + batRend.Count)); } private bool IsBatteryRenderer(Renderer r) { if (batRend.Contains(r) || IsUnder(((Component)r).transform, "Battery") || IsUnder(((Component)r).transform, "Bar")) { return true; } Transform val = ((Component)r).transform; while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)this).transform) { MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>(); foreach (MonoBehaviour val2 in components) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)this && ((object)val2).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0) { batRend.Add(r); return true; } } val = val.parent; } return false; } private static bool IsUnder(Transform t, string part) { Transform val = t; while ((Object)(object)val != (Object)null) { if (((Object)val).name.IndexOf(part, StringComparison.OrdinalIgnoreCase) >= 0) { return true; } val = val.parent; } return false; } private static int[] ColorProps(Material m) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 List<int> list = new List<int>(); Shader val = (((Object)(object)m != (Object)null) ? m.shader : null); if ((Object)(object)val == (Object)null) { return list.ToArray(); } int propertyCount = val.GetPropertyCount(); for (int i = 0; i < propertyCount; i++) { if ((int)val.GetPropertyType(i) == 0) { list.Add(Shader.PropertyToID(val.GetPropertyName(i))); } } return list.ToArray(); } private static Gradient SolidGradient(Color c) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) Gradient val = new Gradient(); val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(c, 0f), new GradientColorKey(c, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }); return val; } private void TintBeams() { //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_013e: 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_014e: 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_01ce: Unknown result type (might be due to invalid IL or missing references) if (Time.time > nextBeamFind) { nextBeamFind = Time.time + 1f; beamList.Clear(); Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !IsUnder(((Component)val).transform, "Drone Icon") && !IsBatteryRenderer(val) && (val is LineRenderer || val is ParticleSystemRenderer || val is TrailRenderer || Classify(((Component)val).transform) == Part.Skip)) { beamList.Add(val); } } } Color orange = Orange; foreach (Renderer beam in beamList) { if (!((Object)(object)beam == (Object)null)) { LineRenderer val2 = (LineRenderer)(object)((beam is LineRenderer) ? beam : null); if ((Object)(object)val2 != (Object)null) { val2.startColor = orange; val2.endColor = orange; val2.colorGradient = SolidGradient(orange); } Material material = beam.material; if (!beamProps.TryGetValue(beam, out var value)) { value = ColorProps(material); beamProps[beam] = value; } int[] array = value; foreach (int num in array) { Color color = material.GetColor(num); material.SetColor(num, new Color(orange.r, orange.g, orange.b, color.a)); } } } } private void ApplyDroneFieldColors() { //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[StunDrone] drone color fields: "); MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this) { continue; } string name = ((object)val).GetType().Name; if (name == "ItemAttributes" || name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0 || val is Graphic) { continue; } Type type = ((object)val).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { string text = fieldInfo.Name.ToLower(); if (fieldInfo.FieldType == typeof(Color) && text.Contains("color")) { fieldInfo.SetValue(val, Orange); if (!fieldColorLogged) { stringBuilder.Append(name).Append('.').Append(fieldInfo.Name) .Append("; "); } } else if (fieldInfo.FieldType == typeof(Gradient) && (text.Contains("color") || text.Contains("gradient"))) { fieldInfo.SetValue(val, SolidGradient(Orange)); if (!fieldColorLogged) { stringBuilder.Append(name).Append('.').Append(fieldInfo.Name) .Append("(gradient); "); } } } type = type.BaseType; } } if (!fieldColorLogged) { fieldColorLogged = true; Debug.Log((object)stringBuilder.ToString()); } } private static void SetNum(object o, string name, float v) { Type type = o.GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field == null)) { if (field.FieldType == typeof(float)) { field.SetValue(o, v); } else if (field.FieldType == typeof(int)) { field.SetValue(o, Mathf.RoundToInt(v)); } break; } type = type.BaseType; } } private static bool GetNum(object o, string name, out float v) { v = 0f; Type type = o.GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field == null)) { if (field.FieldType == typeof(float)) { v = (float)field.GetValue(o); return true; } if (field.FieldType == typeof(int)) { v = (int)field.GetValue(o); return true; } return false; } type = type.BaseType; } return false; } private void SyncBattery() { //IL_020c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)batteryComp == (Object)null) { if (Time.time < nextBatFind) { return; } nextBatFind = Time.time + 1f; MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery") { batteryComp = (Component)(object)val; break; } } if ((Object)(object)batteryComp == (Object)null) { return; } } if (!batteryLogged) { batteryLogged = true; Debug.Log((object)("[StunDrone] ItemBattery found, bars=" + Cap)); } SetNum(batteryComp, "batteryBars", Cap); if (!uiDumped && Time.time > nextBatFind + 3f && batteryLogged) { uiDumped = true; StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery UI dump: "); Graphic[] componentsInChildren2 = batteryComp.GetComponentsInChildren<Graphic>(true); foreach (Graphic val2 in componentsInChildren2) { string text = ((Object)val2).name; Transform parent = ((Component)val2).transform.parent; while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)batteryComp.transform) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } stringBuilder.Append(text).Append(" [").Append(((object)val2).GetType().Name) .Append(((Component)val2).gameObject.activeInHierarchy ? "" : ",off") .Append(", ") .Append(val2.color) .Append("]; "); } Debug.Log((object)stringBuilder.ToString()); } float v; if (lifeVal < 0f) { if (GetNum(batteryComp, "batteryLife", out v) && v >= 0f && v <= 100f) { lifeVal = v; charge = Mathf.Clamp(Mathf.FloorToInt(v * (float)Cap / 100f + 0.001f), 0, Cap); Debug.Log((object)("[StunDrone] restored charge " + charge + "/" + Cap + " from batteryLife=" + v)); } else { lifeVal = 100f * (float)charge / (float)Cap; } lastCharge = charge; } if (GetNum(batteryComp, "batteryLife", out v) && v > lifeVal + 0.01f) { lifeVal = Mathf.Min(100f, v); charge = Mathf.Clamp(Mathf.FloorToInt(lifeVal * (float)Cap / 100f + 0.001f), 0, Cap); } else if (charge < lastCharge) { lifeVal = 100f * (float)charge / (float)Cap; } else if (charge > lastCharge) { lifeVal = Mathf.Max(lifeVal, 100f * (float)charge / (float)Cap); } if (lifeVal >= 99.5f) { lifeVal = 100f; charge = Cap; } lastCharge = charge; SetNum(batteryComp, "batteryLife", lifeVal); if (charge >= Cap) { SetNum(batteryComp, "batteryLifeInt", Cap); } if (Time.time > nextBatDump && charge != dumpedCharge) { nextBatDump = Time.time + 2f; dumpedCharge = charge; StringBuilder stringBuilder2 = new StringBuilder("[StunDrone] ItemBattery dump (charge=" + charge + "/" + Cap + "): "); Type type = ((object)batteryComp).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType == typeof(float) || fieldInfo.FieldType == typeof(int) || fieldInfo.FieldType == typeof(bool)) { stringBuilder2.Append(string.Concat(fieldInfo.Name, "=", fieldInfo.GetValue(batteryComp), "; ")); } } type = type.BaseType; } Debug.Log((object)stringBuilder2.ToString()); } Type type2 = ((object)batteryComp).GetType(); while (type2 != null && type2 != typeof(MonoBehaviour)) { FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo2 in fields) { if (fieldInfo2.FieldType == typeof(float) && fieldInfo2.Name.ToLower().Contains("drain")) { fieldInfo2.SetValue(batteryComp, 0f); } } type2 = type2.BaseType; } } private void LuckTick() { if (charge <= 0 || !ToggleOn()) { luckPrev = null; return; } Component valuableTarget = GetValuableTarget(); if ((Object)(object)valuableTarget == (Object)null) { luckPrev = null; } else if (!object.ReferenceEquals(valuableTarget, luckPrev)) { luckPrev = valuableTarget; if (IsAuthority()) { LuckRoll(valuableTarget); } } } private Component GetValuableTarget() { if ((Object)(object)droneComp == (Object)null) { return null; } Type type = Registrar.FindType("ValuableObject"); if (type == null) { return null; } Type type2 = ((object)droneComp).GetType(); while (type2 != null && type2 != typeof(MonoBehaviour)) { FieldInfo field = type2.GetField("magnetTargetPhysGrabObject", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field == null)) { object? value = field.GetValue(droneComp); Component val = (Component)((value is Component) ? value : null); if ((Object)(object)val == (Object)null) { return null; } FieldInfo field2 = type2.GetField("magnetActive", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 != null && field2.FieldType == typeof(bool) && !(bool)field2.GetValue(droneComp)) { return null; } return val.GetComponentInParent(type); } type2 = type2.BaseType; } return null; } private void LuckRoll(Component vo) { //IL_0209: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0257: 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) //IL_0284: Unknown result type (might be due to invalid IL or missing references) try { int instanceID = ((Object)vo).GetInstanceID(); if (LuckOncePerValuable && luckRolled.Contains(instanceID)) { LuckFloatText.Spawn(FloatPos(vo), "уже играли", new Color(0.8f, 0.8f, 0.8f, 1f), vo.gameObject.layer); DetachDrone(); return; } FieldInfo field = ((object)vo).GetType().GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null || field.FieldType != typeof(float)) { Debug.LogWarning((object)"[LuckyDrone] dollarValueCurrent not found"); return; } float num = (float)field.GetValue(vo); if (num <= 0f) { return; } luckRolled.Add(instanceID); bool flag = Random.value < LuckWinChance; float num4; if (flag) { int num2 = Math.Min(LuckGainMin, LuckGainMax); int num3 = Math.Max(LuckGainMin, LuckGainMax); num4 = num + (float)Random.Range(num2, num3 + 1); } else { float num5 = ((num < LuckBigThreshold) ? LuckLossSmall : LuckLossBig); num4 = Mathf.Max(num - num5, Mathf.Min(num, LuckMinValue)); } num4 = Mathf.Round(num4); field.SetValue(vo, num4); try { PhotonView component = vo.GetComponent<PhotonView>(); if ((Object)(object)component != (Object)null) { component.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { num4 }); } } catch (Exception ex) { Debug.LogWarning((object)("[LuckyDrone] RPC: " + ex.Message)); } charge--; float num6 = num4 - num; string text = Mathf.Abs(num6).ToString("N0", CultureInfo.InvariantCulture); LuckFloatText.Spawn(FloatPos(vo), (flag ? "+$" : "-$") + text, flag ? new Color(0.2f, 1f, 0.3f, 1f) : new Color(1f, 0.15f, 0.15f, 1f), vo.gameObject.layer); PlayLuckSound(flag ? LuckWinSound : LuckLoseSound, vo.transform.position); DetachDrone(); Debug.Log((object)("[LuckyDrone] " + ((Object)vo).name + ": " + num + " -> " + num4 + " (" + (flag ? "win" : "lose") + "), charge=" + charge)); } catch (Exception ex) { Debug.LogWarning((object)("[LuckyDrone] roll failed: " + ex.Message)); } } private static Vector3 FloatPos(Component vo) { //IL_0009: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) Bounds bounds = default(Bounds); ((Bounds)(ref bounds))..ctor(vo.transform.position, Vector3.zero); bool flag = false; Renderer[] componentsInChildren = vo.GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(val is ParticleSystemRenderer)) { if (!flag) { bounds = val.bounds; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } } } return new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y + 0.3f, ((Bounds)(ref bounds)).center.z); } private static void PlayLuckSound(string clipName, Vector3 pos) { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(clipName) || LuckSoundVolume <= 0f) { return; } try { if (!luckClips.TryGetValue(clipName, out var value) || (Object)(object)value == (Object)null) { value = null; AudioClip[] array = Resources.FindObjectsOfTypeAll<AudioClip>(); foreach (AudioClip val in array) { if ((Object)(object)val != (Object)null && string.Equals(((Object)val).name, clipName, StringComparison.OrdinalIgnoreCase)) { value = val; break; } } luckClips[clipName] = value; if ((Object)(object)value == (Object)null) { Debug.LogWarning((object)("[LuckyDrone] audio clip not found: " + clipName)); } } if (!((Object)(object)value == (Object)null)) { if ((int)value.loadState != 2) { value.LoadAudioData(); } AudioSource.PlayClipAtPoint(value, pos, Mathf.Clamp01(LuckSoundVolume)); } } catch (Exception ex) { Debug.LogWarning((object)("[LuckyDrone] sound: " + ex.Message)); } } private void DetachDrone() { try { Type type = Registrar.FindType("ItemToggle"); if (type == null) { return; } Component val = ((Component)this).GetComponentInChildren(type, true); if ((Object)(object)val == (Object)null) { val = ((Component)this).GetComponentInParent(type); } if ((Object)(object)val == (Object)null) { return; } bool flag = CallMethod(val, "ToggleItem", false, -1); Type type2 = ((object)val).GetType(); while (type2 != null) { FieldInfo field = type2.GetField("toggleState", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { field.SetValue(val, false); break; } type2 = type2.BaseType; } luckPrev = null; if (!flag) { Debug.Log((object)"[LuckyDrone] ToggleItem method not found, toggleState set directly"); } } catch (Exception ex) { Debug.LogWarning((object)("[LuckyDrone] detach: " + ex.Message)); } } private static bool IsAuthority() { try { return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient; } catch { return true; } } private static bool IntMember(object o, string name, out int v) { v = 0; Type type = o.GetType(); while (type != null) { FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(int)) { v = (int)field.GetValue(o); return true; } PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(int) && property.CanRead && property.GetIndexParameters().Length == 0) { try { v = (int)property.GetValue(o, null); return true; } catch { return false; } } type = type.BaseType; } return false; } private static Component FindHealth(PlayerAvatar p) { Type type = ((object)p).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType.Name == "PlayerHealth") { object? value = fieldInfo.GetValue(p); Component val = (Component)((value is Component) ? value : null); if ((Object)(object)val != (Object)null) { return val; } } } type = type.BaseType; } return FindComp((Component)(object)p, "PlayerHealth"); } private bool NeedsHeal(PlayerAvatar p) { if ((Object)(object)p == (Object)null) { return false; } if (BoolMember(p, "isDisabled") || BoolMember(p, "deadSet")) { return false; } Component val = FindHealth(p); if ((Object)(object)val == (Object)null) { return true; } if (IntMember(val, "health", out var v) && IntMember(val, "maxHealth", out var v2)) { return v < v2; } return true; } private void HealTick() { object obj = stunned; PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null); if ((Object)(object)val == (Object)null || Time.time < nextHeal) { return; } nextHeal = Time.time + HealInterval; if (!IsAuthority() || !NeedsHeal(val)) { return; } Component val2 = FindHealth(val); if ((Object)(object)val2 == (Object)null) { if (!healWarned) { healWarned = true; Debug.LogWarning((object)"[HealDrone] PlayerHealth not found"); } } else if (CallMethod(val2, "Heal", HealAmount, true) || CallMethod(val2, "Heal", HealAmount)) { charge--; Debug.Log((object)("[HealDrone] healed " + HealAmount + " HP, charge=" + charge)); } else if (!healWarned) { healWarned = true; Debug.LogWarning((object)"[HealDrone] PlayerHealth.Heal call failed"); } } private void StunPlayer(PlayerAvatar p) { try { if ((Object)(object)tumbleCache == (Object)null || (Object)(object)cachedFor != (Object)(object)p) { tumbleCache = FindTumble(p); cachedFor = p; } Component val = tumbleCache; if ((Object)(object)val == (Object)null) { if (!tumbleWarned) { tumbleWarned = true; Debug.LogWarning((object)"[StunDrone] PlayerTumble not found"); } return; } if (!CallMethod(val, "TumbleRequest", true, true) && !tumbleWarned) { tumbleWarned = true; Debug.LogWarning((object)"[StunDrone] TumbleRequest call failed"); } CallMethod(val, "TumbleOverrideTime", 3f); } catch (Exception ex) { Debug.LogWarning((object)("[StunDrone] StunPlayer: " + ex.Message)); } } private void StunEnemy(Enemy e) { try { Component val = FindStun((Component)(object)e); if ((Object)(object)val != (Object)null && CallMethod(val, "Set", 1.5f)) { if (!stunOk) { stunOk = true; Debug.Log((object)("[StunDrone] enemy stunned via " + ((object)val).GetType().Name + ".Set on " + ((Object)e).name)); } return; } if ((Object)(object)val != (Object)null && !stunWarned2) { stunWarned2 = true; StringBuilder stringBuilder = new StringBuilder("[StunDrone] " + ((object)val).GetType().Name + " methods: "); MethodInfo[] methods = ((object)val).GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { stringBuilder.Append(methodInfo.Name).Append('('); ParameterInfo[] parameters = methodInfo.GetParameters(); foreach (ParameterInfo parameterInfo in parameters) { stringBuilder.Append(parameterInfo.ParameterType.Name).Append(' '); } stringBuilder.Append("); "); } Debug.LogWarning((object)stringBuilder.ToString()); } if ((Object)(object)val == (Object)null && !noStunLogged.Contains(((Object)e).name)) { noStunLogged.Add(((Object)e).name); Debug.LogWarning((object)("[StunDrone] enemy '" + ((Object)e).name + "' has no stun state -> freezing manually")); } FreezeEnemy(e); bool flag = false; MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val2 in componentsInChildren) { if ((Object)(object)val2 == (Object)null) { continue; } Type type = ((object)val2).GetType(); while (type != null && type != typeof(MonoBehaviour)) { FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { field.SetValue(val2, true); flag = true; } PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(bool) && property.CanWrite) { try { property.SetValue(val2, true, null); flag = true; } catch { } } type = type.BaseType; } } if (!flag) { Debug.LogWarning((object)"[StunDrone] no way to stun enemy (no EnemyState*Stun*, no Stunned flag)"); } else if (!stunWarned) { stunWarned = true; Debug.LogWarning((object)"[StunDrone] used Stunned flag fallback (state component not found) - may not actually stop the AI"); } } catch (Exception ex) { Debug.LogWarning((object)("[StunDrone] StunEnemy: " + ex.Message)); } } private void FreezeEnemy(Enemy e) { //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { string name = ((object)val).GetType().Name; if (name == "EnemyNavMeshAgent") { CallMethod(val, "Disable", 0.3f); } } } Rigidbody[] componentsInChildren2 = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<Rigidbody>(true); foreach (Rigidbody val2 in componentsInChildren2) { if ((Object)(object)val2 != (Object)null && !val2.isKinematic) { val2.linearVelocity = Vector3.zero; val2.angularVelocity = Vector3.zero; } } } private void DefenseTick(PlayerAvatar p) { DefenseHighlight defenseHighlight = ((Component)p).GetComponent<DefenseHighlight>(); if ((Object)(object)defenseHighlight == (Object)null) { defenseHighlight = ((Component)p).gameObject.AddComponent<DefenseHighlight>(); } defenseHighlight.SetActive(active: true); DefenseHudOverlay.SetProtected(p, active: true); if (!IsAuthority()) { return; } Component val = FindHealth(p); if ((Object)(object)val == (Object)null || !IntMember(val, "health", out var v)) { return; } if ((Object)(object)lastDefPlayer != (Object)(object)p) { lastDefPlayer = p; lastDefHp = v; return; } if (v < lastDefHp && v > 0) { int num = lastDefHp - v; CallMethod(val, "Heal", num, false); IntMember(val, "health", out v); } lastDefHp = v; } private void ClearDefense(object target) { lastDefPlayer = null; lastDefHp = -1; PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null); if (!((Object)(object)val == (Object)null)) { DefenseHighlight component = ((Component)val).GetComponent<DefenseHighlight>(); if ((Object)(object)component != (Object)null) { component.SetActive(active: false); } DefenseHudOverlay.SetProtected(val, active: false); } } } public class HealDroneLogic : StunDroneLogic { } public class DefenseDroneLogic : StunDroneLogic { } public class LuckDroneLogic : StunDroneLogic { } public class LuckFloatText : MonoBehaviour { private const float Life = 2.4f; private TextMesh main; private TextMesh shadow; private Vector3 startPos; private float t0; private Color baseColor; public static void Spawn(Vector3 pos, string text, Color col, int layer) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_001a: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00c8: 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_00da: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("LuckFloatText"); val.layer = layer; val.transform.position = pos; LuckFloatText luckFloatText = val.AddComponent<LuckFloatText>(); luckFloatText.startPos = pos; luckFloatText.t0 = Time.time; Font val2 = null; try { val2 = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf"); } catch { } if ((Object)(object)val2 == (Object)null) { try { val2 = Resources.GetBuiltinResource<Font>("Arial.ttf"); } catch { } } if ((Object)(object)val2 == (Object)null) { val2 = Font.CreateDynamicFontFromOSFont("Arial", 64); } luckFloatText.shadow = MakeText(val.transform, val2, text, Color.black, new Vector3(0.012f, -0.012f, 0.01f), layer); luckFloatText.main = MakeText(val.transform, val2, text, col, Vector3.zero, layer); luckFloatText.baseColor = col; } private static TextMesh MakeText(Transform parent, Font font, string text, Color col, Vector3 offset, int layer) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0029: 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) GameObject val = new GameObject("t"); val.layer = layer; val.transform.SetParent(parent, false); val.transform.localPosition = offset; TextMesh val2 = val.AddComponent<TextMesh>(); val2.font = font; val2.text = text; val2.fontSize = 64; val2.characterSize = 0.05f; val2.fontStyle = (FontStyle)1; val2.anchor = (TextAnchor)4; val2.alignment = (TextAlignment)1; val2.color = col; MeshRenderer component = val.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null && (Object)(object)font != (Object)null) { ((Renderer)component).sharedMaterial = font.material; } return val2; } private void LateUpdate() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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_0116: 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_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0169: 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_017f: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) float num = (Time.time - t0) / 2.4f; if (num >= 1f) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } ((Component)this).transform.position = startPos + Vector3.up * (num * 1.3f); Camera val = Camera.main; float num2 = 1f; if ((Object)(object)val != (Object)null) { ((Component)this).transform.rotation = ((Component)val).transform.rotation; num2 = Mathf.Clamp(Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) * 0.2f, 0.7f, 4f); } float num3 = ((num < 0.08f) ? Mathf.Lerp(0.4f, 1.15f, num / 0.08f) : ((num < 0.16f) ? Mathf.Lerp(1.15f, 1f, (num - 0.08f) / 0.08f) : 1f)); ((Component)this).transform.localScale = Vector3.one * num2 * num3; float num4 = ((num < 0.65f) ? 1f : (1f - (num - 0.65f) / 0.35f)); if ((Object)(object)main != (Object)null) { Color color = baseColor; color.a = num4; main.color = color; } if ((Object)(object)shadow != (Object)null) { shadow.color = new Color(0f, 0f, 0f, num4); } } } public static class DefenseGuard { private static readonly BindingFlags BF = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static FieldInfo avatarField; private static FieldInfo healthField; public static void Install(ManualLogSource log) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown try { Type type = typeof(StatsManager).Assembly.GetType("PlayerHealth"); if (type == null) { log.LogWarning((object)"[DefenseGuard] PlayerHealth not found"); return; } Harmony val = new Harmony("user.defensedrone.guard"); HarmonyMethod val2 = new HarmonyMethod(typeof(DefenseGuard).GetMethod("HurtPrefix", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); int num = 0; MethodInfo[] methods = type.GetMethods(BF | BindingFlags.DeclaredOnly); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "Hurt")) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length != 0 && !(parameters[0].ParameterType != typeof(int))) { val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } } } avatarField = type.GetField("playerAvatar", BF); healthField = type.GetField("health", BF); log.LogInfo((object)("[DefenseGuard] patched PlayerHealth.Hurt overloads: " + num + ", avatarField=" + (avatarField != null) + ", healthField=" + (healthField != null))); } catch (Exception ex) { log.LogWarning((object)("[DefenseGuard] install failed: " + ex.Message)); } } private static void HurtPrefix(object __instance, ref int __0) { try { if (__0 <= 0 || __instance == null || avatarField == null || healthField == null) { return; } object? value = avatarField.GetValue(__instance); PlayerAvatar val = (PlayerAvatar)((value is PlayerAvatar) ? value : null); if (!((Object)(object)val == (Object)null) && DefenseHudOverlay.IsProtectedAvatar(val)) { int num = (int)healthField.GetValue(__instance); if (num <= 1) { __0 = 0; } else if (__0 >= num) { __0 = num - 1; } } } catch { } } } public class DefenseHudOverlay : MonoBehaviour { private struct GraphicState { public Graphic graphic; public Color origColor; } private static DefenseHudOverlay instance; private static readonly Dictionary<int, float> protectedUntil = new Dictionary<int, float>(); private static Texture2D shieldTex; public static float ShieldOffsetX = 8f; public static float ShieldOffsetY = 0f; public static float ShieldScale = 0.7f; private readonly List<GraphicState> tintedGraphics = new List<GraphicState>(); private GameObject shieldBadgeGo; private RawImage shieldBadgeImg; private bool hudApplied; private float nextScan; public static bool IsProtectedAvatar(PlayerAvatar p) { if ((Object)(object)p == (Object)null) { return false; } float value; return protectedUntil.TryGetValue(((Object)p).GetInstanceID(), out value) && value >= Time.time; } public static void SetProtected(PlayerAvatar p, bool active) { if (!((Object)(object)p == (Object)null)) { int instanceID = ((Object)p).GetInstanceID(); if (active) { protectedUntil[instanceID] = Time.time + 1.5f; } else { protectedUntil.Remove(instanceID); } EnsureInstance(); } } private static void EnsureInstance() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown if (!((Object)(object)instance != (Object)null)) { GameObject val = new GameObject("DefenseDroneHudOverlay"); Object.DontDestroyOnLoad((Object)(object)val); instance = val.AddComponent<DefenseHudOverlay>(); } } private static bool IsLocalPlayerProtected() { if (protectedUntil.Count == 0) { return false; } float time = Time.time; List<int> list = new List<int>()