Decompiled source of Valheim Ancient Runes v0.13.0

BepInEx/plugins/AncientRunes/BossMagic.Test.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BossMagic.Test")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.13.0.0")]
[assembly: AssemblyInformationalVersion("0.13.0")]
[assembly: AssemblyProduct("BossMagic.Test")]
[assembly: AssemblyTitle("BossMagic.Test")]
[assembly: AssemblyVersion("0.13.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BossMagic.Test
{
	internal static class BeaconEffects
	{
		private static GameObject holder;

		private static GameObject template;

		internal static int ParticleCount;

		internal static int AudioCount;

		internal static int Plays;

		internal static bool Safe;

		internal static GameObject LastEffect;

		internal static void Prepare()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)template))
			{
				return;
			}
			Incinerator component = PrefabManager.Instance.GetPrefab("incinerator").GetComponent<Incinerator>();
			GameObject val = (GameObject)AccessTools.Field(typeof(Incinerator), "m_lightingAOEs").GetValue(component);
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Obliterator lightning visual missing");
			}
			holder = new GameObject("BossMagic_BeaconTemplates");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			template = Object.Instantiate<GameObject>(val, holder.transform, false);
			((Object)template).name = "BossMagic_BeaconVisual";
			MonoBehaviour[] componentsInChildren = template.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if (!(val2 is ZSFX) && !(val2 is LightFlicker))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			Collider[] componentsInChildren2 = template.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Rigidbody[] componentsInChildren3 = template.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			ParticleSystem[] componentsInChildren4 = template.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val3 in componentsInChildren4)
			{
				MainModule main = val3.main;
				((MainModule)(ref main)).loop = false;
				((MainModule)(ref main)).startDelay = MinMaxCurve.op_Implicit(0f);
				((MainModule)(ref main)).stopAction = (ParticleSystemStopAction)0;
				Plugin instance = Plugin.instance;
				string[] obj = new string[6]
				{
					"BOSSMAGIC_BEACON_PARTICLE name=",
					((Object)val3).name,
					" local=",
					((object)((Component)val3).transform.localPosition/*cast due to .constrained prefix*/).ToString(),
					" size=",
					null
				};
				MinMaxCurve startSize = ((MainModule)(ref main)).startSize;
				obj[5] = ((MinMaxCurve)(ref startSize)).constantMax.ToString();
				instance.InfoLog(string.Concat(obj));
			}
			ZSFX[] componentsInChildren5 = template.GetComponentsInChildren<ZSFX>(true);
			foreach (ZSFX obj2 in componentsInChildren5)
			{
				obj2.m_minVol *= 0.65f;
				obj2.m_maxVol *= 0.65f;
				obj2.m_minDelay = (obj2.m_maxDelay = 0f);
				obj2.m_useVibration = false;
			}
			template.SetActive(false);
			ParticleCount = template.GetComponentsInChildren<ParticleSystem>(true).Length;
			AudioCount = template.GetComponentsInChildren<ZSFX>(true).Sum((ZSFX s) => s.m_audioClips.Count((AudioClip c) => Object.op_Implicit((Object)(object)c)));
			Safe = template.GetComponentsInChildren<Aoe>(true).Length == 0 && template.GetComponentsInChildren<ZNetView>(true).Length == 0 && template.GetComponentsInChildren<Collider>(true).Length == 0;
			Plugin.instance.InfoLog("BOSSMAGIC_BEACON_EFFECT source=" + ((Object)val).name + " particles=" + ParticleCount + " audio=" + AudioCount + " safe=" + Safe);
		}

		internal static void Play(Vector3 point)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Prepare();
			LastEffect = Object.Instantiate<GameObject>(template, point, Quaternion.identity);
			LastEffect.SetActive(true);
			Plays++;
			Object.Destroy((Object)(object)LastEffect, 8f);
		}
	}
	internal static class BeaconSystem
	{
		private sealed class BeaconCommand : ConsoleCommand
		{
			public override string Name => "bossmagic_beacon";

			public override string Help => "Entrega a runa Lightning Beacon experimental.";

			public override void Run(string[] args)
			{
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)ZNet.instance))
				{
					Give(Player.m_localPlayer);
				}
			}
		}

		internal const string RuneName = "BossMagic_BeaconRune";

		internal static ConfigEntry<float> Damage;

		internal static ConfigEntry<float> Cost;

		internal static ConfigEntry<float> Cooldown;

		internal static ConfigEntry<float> Range;

		internal static bool Ready;

		internal static float NextCast;

		internal static int CastCount;

		private static Player lastCaster;

		private static Character pendingTarget;

		private static Player pendingCaster;

		private static bool pendingConsumed;

		private static readonly ConditionalWeakTable<HitData, object> pureHits = new ConditionalWeakTable<HitData, object>();

		internal static void Initialize(Plugin host, Harmony harmony)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			Damage = Bind(host, "PureDamage", 100f, 1f, 5000f, "Dano puro base. Ignora armadura/resistencias por tipo; modificadores gerais continuam validos.");
			Cost = Bind(host, "ActivationStamina", 25f, 0f, 200f, "Custo por raio. Sem alvo valido, nao cobra estamina.");
			Cooldown = Bind(host, "Cooldown", 6f, 0f, 120f, "Recarga em segundos, contada desde o raio.");
			Range = Bind(host, "Range", 50f, 5f, 100f, "Alcance em metros. Exige inimigo na mira, linha de visao e 30 metros livres acima do alvo.");
			PrefabManager.OnVanillaPrefabsAvailable += Register;
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new BeaconCommand());
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Humanoid), "UseItem", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BeaconSystem), "Use", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Character), "RPC_Damage", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BeaconSystem), "TagReceivedHit", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(HitData), "ApplyModifier", new Type[1] { typeof(float) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BeaconSystem), "ModifyPureDamage", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static ConfigEntry<float> Bind(Plugin host, string key, float value, float min, float max, string text)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			return ((BaseUnityPlugin)host).Config.Bind<float>("Beacon", key, value, new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private static void Register()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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)
			CustomItem val = new CustomItem("BossMagic_BeaconRune", "Stone", new ItemConfig
			{
				Name = "Runa de Lightning Beacon",
				Description = "Invoca um raio do ceu sobre o inimigo na mira. Dano puro, sem explosao em area. Requer caminho livre e alvo descoberto. Use na hotbar mantendo suas armas."
			});
			SharedData shared = val.ItemDrop.m_itemData.m_shared;
			shared.m_itemType = (ItemType)1;
			shared.m_maxStackSize = 1;
			shared.m_maxQuality = 1;
			shared.m_weight = 0.2f;
			Texture2D val2 = new Texture2D(64, 64, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					Vector2 val3 = new Vector2((float)(j - 32), (float)(i - 32));
					float magnitude = ((Vector2)(ref val3)).magnitude;
					bool flag = i > 14 && i < 55 && Math.Abs(j - (27 + i % 13)) < 3;
					bool flag2 = Mathf.Abs(Mathf.Pow(((float)j - 32f) / 19f, 2f) + Mathf.Pow(((float)i - 14f) / 6f, 2f) - 1f) < 0.25f;
					array[i * 64 + j] = (Color)((magnitude > 29f) ? Color.clear : ((flag || flag2) ? new Color(0.9f, 1f, 1f) : new Color(0.12f, 0.17f, 0.32f)));
				}
			}
			val2.SetPixels(array);
			val2.Apply();
			shared.m_icons = (Sprite[])(object)new Sprite[1] { Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)) };
			if (!ItemManager.Instance.AddItem(val))
			{
				throw new InvalidOperationException("Beacon registration failed");
			}
			Ready = true;
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			Plugin.instance.InfoLog("BOSSMAGIC_BEACON_REGISTERED");
		}

		private static bool Use(Humanoid __instance, Inventory inventory, ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null || ((Object)item.m_dropPrefab).name != "BossMagic_BeaconRune")
			{
				return true;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (Object.op_Implicit((Object)(object)val) && (Object)(object)val == (Object)(object)Player.m_localPlayer && (inventory == null || inventory == ((Humanoid)val).GetInventory()) && ((Humanoid)val).GetInventory().ContainsItem(item))
			{
				TryCast(val);
			}
			return false;
		}

		internal static Character FindTarget(Player player, out string reason)
		{
			//IL_0024: 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_002e: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			reason = "Mire diretamente em um inimigo.";
			if (!Object.op_Implicit((Object)(object)Camera.main))
			{
				return null;
			}
			Ray val = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f));
			foreach (RaycastHit item in from h in Physics.RaycastAll(val, Range.Value + Vector3.Distance(((Ray)(ref val)).origin, ((Character)player).GetEyePoint()), MagicSystem.CollisionMask, (QueryTriggerInteraction)1)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				Character componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Character>();
				if (!((Object)(object)componentInParent == (Object)(object)player))
				{
					if (!MagicSystem.IsTarget(componentInParent, player))
					{
						return null;
					}
					if (Vector3.Distance(((Character)player).GetEyePoint(), ((RaycastHit)(ref current)).point) > Range.Value)
					{
						reason = "Alvo fora do alcance.";
						return null;
					}
					if (Physics.Linecast(((Character)player).GetEyePoint(), ((RaycastHit)(ref current)).point, MagicSystem.WorldMask, (QueryTriggerInteraction)1))
					{
						reason = "O caminho ate o alvo esta bloqueado.";
						return null;
					}
					if (Physics.Raycast(componentInParent.GetCenterPoint(), Vector3.up, 30f, MagicSystem.WorldMask, (QueryTriggerInteraction)1))
					{
						reason = "O alvo esta sob cobertura.";
						return null;
					}
					return componentInParent;
				}
			}
			return null;
		}

		internal static bool TryCast(Player player)
		{
			//IL_00c2: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return false;
			}
			if (((Character)player).IsDead() || ((Character)player).InCutscene() || ((Character)player).IsTeleporting() || ((Character)player).IsAttached() || ((Character)player).InAttack() || ((Character)player).IsDodgeInvincible() || ((Character)player).IsStaggering())
			{
				return false;
			}
			if ((Object)(object)lastCaster != (Object)(object)player)
			{
				NextCast = 0f;
				lastCaster = player;
			}
			if (Time.time < NextCast)
			{
				MagicSystem.Say(player, "Beacon recarregando.");
				return false;
			}
			string reason;
			Character val = FindTarget(player, out reason);
			if (!Object.op_Implicit((Object)(object)val))
			{
				MagicSystem.Say(player, reason);
				return false;
			}
			if (!((Character)player).HaveStamina(Cost.Value))
			{
				MagicSystem.Say(player, "Estamina insuficiente para Beacon.");
				return false;
			}
			BeaconEffects.Prepare();
			Vector3 position = ((Component)val).transform.position;
			((Character)player).UseStamina(Cost.Value);
			NextCast = Time.time + Cooldown.Value;
			NetworkMagic.Beacon(player, val);
			BeaconEffects.Play(position);
			NetworkMagic.BeaconVisual(player, position);
			CastCount++;
			Plugin.instance.InfoLog("BOSSMAGIC_BEACON_CAST target=" + ((Object)val).name + " pureBase=" + Damage.Value);
			return true;
		}

		internal static HitData MakeHit(Player player, Character target, float amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			HitData val = new HitData
			{
				m_point = target.GetCenterPoint(),
				m_dir = Vector3.down,
				m_ranged = true,
				m_dodgeable = true,
				m_blockable = false,
				m_backstabBonus = 1f,
				m_staggerMultiplier = 0f,
				m_pushForce = 0f,
				m_damage = 
				{
					m_damage = amount
				}
			};
			val.SetAttacker((Character)(object)player);
			return val;
		}

		internal static void ApplyPureHit(Player player, Character target, float amount)
		{
			Character val = pendingTarget;
			Player val2 = pendingCaster;
			bool flag = pendingConsumed;
			pendingTarget = target;
			pendingCaster = player;
			pendingConsumed = false;
			try
			{
				target.Damage(MakeHit(player, target, amount));
			}
			finally
			{
				pendingTarget = val;
				pendingCaster = val2;
				pendingConsumed = flag;
			}
		}

		private static void TagReceivedHit(Character __instance, HitData __1)
		{
			if (!pendingConsumed && Object.op_Implicit((Object)(object)pendingTarget) && !((Object)(object)__instance != (Object)(object)pendingTarget) && !((Object)(object)__1.GetAttacker() != (Object)(object)pendingCaster) && !(__1.m_damage.m_damage <= 0f))
			{
				pendingConsumed = true;
				pureHits.GetValue(__1, (HitData _) => new object());
			}
		}

		private static void ModifyPureDamage(HitData __instance, float __0)
		{
			if (pureHits.TryGetValue(__instance, out var _))
			{
				__instance.m_damage.m_damage *= __0;
			}
		}

		internal static ItemData Give(Player player)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("BossMagic_BeaconRune");
			ItemData val = prefab.GetComponent<ItemDrop>().m_itemData.Clone();
			val.m_dropPrefab = prefab;
			if (!((Humanoid)player).GetInventory().AddItem(val))
			{
				MagicSystem.Say(player, "Inventario cheio.");
				return null;
			}
			return val;
		}
	}
	public sealed class BeaconTestModifier : StatusEffect
	{
		public float Factor = 1f;

		public override void OnDamaged(HitData hit, Character attacker)
		{
			hit.ApplyModifier(Factor);
		}
	}
	internal static class GameplayTest
	{
		private static bool started;

		private static Plugin plugin;

		private static readonly Dictionary<ConfigEntryBase, object> savedConfig = new Dictionary<ConfigEntryBase, object>();

		private static bool savedAutoSave;

		private static readonly List<GameObject> woodFixtures = new List<GameObject>();

		private static void RestoreTestConfig()
		{
			foreach (KeyValuePair<ConfigEntryBase, object> item in savedConfig)
			{
				item.Key.BoxedValue = item.Value;
			}
			savedConfig.Clear();
			((BaseUnityPlugin)plugin).Config.SaveOnConfigSet = savedAutoSave;
		}

		private static void ClearWoodFixtures()
		{
			foreach (GameObject woodFixture in woodFixtures)
			{
				if (Object.op_Implicit((Object)(object)woodFixture) && Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					ZNetScene.instance.Destroy(woodFixture);
				}
			}
			woodFixtures.Clear();
		}

		internal static void OnMenu(Plugin host)
		{
			if (started || Array.IndexOf(Environment.GetCommandLineArgs(), "-bossmagic-gameplay-test") < 0)
			{
				return;
			}
			started = true;
			plugin = host;
			savedAutoSave = ((BaseUnityPlugin)host).Config.SaveOnConfigSet;
			((BaseUnityPlugin)host).Config.SaveOnConfigSet = false;
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in ((BaseUnityPlugin)host).Config)
			{
				savedConfig[item.Value] = item.Value.BoxedValue;
				item.Value.BoxedValue = item.Value.DefaultValue;
			}
			((MonoBehaviour)host).StartCoroutine(Guard(Run()));
		}

		private static IEnumerator Guard(IEnumerator test)
		{
			float start = Time.realtimeSinceStartup;
			while (true)
			{
				object current;
				try
				{
					if (Time.realtimeSinceStartup - start > 240f)
					{
						throw new TimeoutException("Gameplay test timed out.");
					}
					if (!test.MoveNext())
					{
						break;
					}
					current = test.Current;
				}
				catch (Exception ex)
				{
					plugin.ErrorLog("BOSSMAGIC_GAMEPLAY_FAIL " + ex);
					ClearWoodFixtures();
					if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
					{
						TestArea.Reset(((Component)Player.m_localPlayer).transform.position, 300f);
					}
					RestoreTestConfig();
					Application.Quit(3);
					break;
				}
				yield return current;
			}
		}

		private static void Require(bool value, string message)
		{
			if (!value)
			{
				throw new InvalidOperationException(message);
			}
			plugin.InfoLog("BOSSMAGIC_ASSERT_PASS " + message);
		}

		private static ItemData Add(Player player, string prefabName, int slot)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				throw new InvalidOperationException("Missing " + prefabName);
			}
			ItemData val = prefab.GetComponent<ItemDrop>().m_itemData.Clone();
			val.m_dropPrefab = prefab;
			val.m_stack = 1;
			if (!((Humanoid)player).GetInventory().AddItem(val))
			{
				throw new InvalidOperationException("Inventory full");
			}
			val.m_gridPos = new Vector2i(slot, 0);
			return val;
		}

		private static Character Target(Vector3 point, bool tamed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return TestArea.Spawn(point, tamed, frozen: true);
		}

		private static void Aim(Player player, Vector3 target)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Character)player).GetEyePoint() - Vector3.forward * 3f + Vector3.up * 2f;
			((Component)Camera.main).transform.position = val;
			((Component)Camera.main).transform.rotation = Quaternion.LookRotation(target - val);
			Vector3 val2 = target - ((Character)player).GetEyePoint();
			((Character)player).SetLookDir(((Vector3)(ref val2)).normalized, 0f);
		}

		private static void CaptureView(string filename = "lightning-cast.png")
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			RenderTexture targetTexture = main.targetTexture;
			RenderTexture active = RenderTexture.active;
			RenderTexture temporary = RenderTexture.GetTemporary(1280, 720, 24);
			Texture2D val = new Texture2D(1280, 720, (TextureFormat)3, false);
			try
			{
				main.targetTexture = temporary;
				main.Render();
				RenderTexture.active = temporary;
				val.ReadPixels(new Rect(0f, 0f, 1280f, 720f), 0, 0);
				val.Apply();
				File.WriteAllBytes(Path.GetFullPath(Path.Combine(Paths.GameRootPath, "..", "evidence", filename)), ImageConversion.EncodeToPNG(val));
			}
			finally
			{
				main.targetTexture = targetTexture;
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				Object.Destroy((Object)(object)val);
			}
		}

		private static IEnumerator RunNature(Player player)
		{
			float stable = 0f;
			while (stable < 3f)
			{
				stable = ((((Character)player).InCutscene() || ((Character)player).IsTeleporting()) ? 0f : (stable + Time.deltaTime));
				yield return null;
			}
			NatureBlessing.Prepare();
			Require(((Object)NatureBlessing.Native).name == "SE_Greydwarf_shaman_heal", "native Shaman healing source resolved");
			((Humanoid)player).GetInventory().RemoveAll();
			ItemData sword = Add(player, "SwordBronze", 0);
			((Humanoid)player).EquipItem(sword, false);
			Require(RuneBag.Accepts(Add(player, "BossMagic_NatureBlessingRune", 1)), "Nature rune accepted by default bag");
			Character ally = Target(((Component)player).transform.position + Vector3.right * 2f, tamed: true);
			Character enemy = Target(((Component)player).transform.position + Vector3.left * 2f, tamed: false);
			Character far = Target(((Component)player).transform.position + Vector3.forward * 10f, tamed: true);
			yield return (object)new WaitForSeconds(0.3f);
			((Character)player).SetHealth(5f);
			ally.SetHealth(5f);
			enemy.SetHealth(5f);
			far.SetHealth(5f);
			((Character)player).AddStamina(200f);
			NatureBlessing.NextCast = 0f;
			Cursor.visible = false;
			Cursor.lockState = (CursorLockMode)1;
			Plugin obj = plugin;
			string[] obj2 = new string[16]
			{
				"NATURE_STATE dead=",
				((Character)player).IsDead().ToString(),
				" attack=",
				((Character)player).InAttack().ToString(),
				" teleport=",
				((Character)player).IsTeleporting().ToString(),
				" cutscene=",
				((Character)player).InCutscene().ToString(),
				" attached=",
				((Character)player).IsAttached().ToString(),
				" stagger=",
				((Character)player).IsStaggering().ToString(),
				" dodge=",
				((Character)player).IsDodgeInvincible().ToString(),
				" slot=",
				null
			};
			ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(1, 0);
			object obj3;
			if (itemAt == null)
			{
				obj3 = null;
			}
			else
			{
				GameObject dropPrefab = itemAt.m_dropPrefab;
				obj3 = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
			}
			obj2[15] = (string)obj3;
			obj.InfoLog(string.Concat(obj2));
			float stamina = player.GetStamina();
			AccessTools.Method(typeof(Player), "UseHotbarItem", (Type[])null, (Type[])null).Invoke(player, new object[1] { 2 });
			Require(NatureBlessing.NextCast > Time.time, "Nature rune activates from normal hotbar");
			Require(Mathf.Abs(player.GetStamina() - (stamina - NatureBlessing.Cost.Value)) < 0.1f, "Nature charges activation stamina");
			Require(((Character)player).GetHealth() == 5f && ally.GetHealth() == 5f, "Nature healing is not instantaneous");
			int hash = StringExtensionMethods.GetStableHashCode("BossMagic_NatureBlessing");
			Require(Object.op_Implicit((Object)(object)((Character)player).GetSEMan().GetStatusEffect(hash)) && Object.op_Implicit((Object)(object)ally.GetSEMan().GetStatusEffect(hash)), "Nature applies to caster and nearby tame");
			Require(!Object.op_Implicit((Object)(object)enemy.GetSEMan().GetStatusEffect(hash)) && !Object.op_Implicit((Object)(object)far.GetSEMan().GetStatusEffect(hash)), "Nature excludes enemies and allies outside radius");
			Require(!NatureBlessing.TryCast(player), "Nature cooldown blocks repeated cast");
			yield return (object)new WaitForSeconds(1.3f);
			Require(((Character)player).GetHealth() > 5f && ally.GetHealth() > 5f && ally.GetHealth() < 25f, "Nature restores health gradually");
			RuneHotbarTest.Capture("blessing-of-nature.png");
			yield return (object)new WaitForSeconds(4f);
			Require(!Object.op_Implicit((Object)(object)((Character)player).GetSEMan().GetStatusEffect(hash)) && !Object.op_Implicit((Object)(object)ally.GetSEMan().GetStatusEffect(hash)), "Nature expires after configured duration");
			Require(ally.GetHealth() >= 24.9f && ally.GetHealth() < 25.2f, "Nature delivers configured total healing");
			Require(enemy.GetHealth() == 5f && far.GetHealth() == 5f, "Nature does not heal excluded creatures");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword, "Nature preserves equipped weapon");
			Require(NatureBlessing.Native.m_healthOverTime == 20f && ((StatusEffect)NatureBlessing.Native).m_ttl == 4f, "Native Shaman settings remain unchanged");
			plugin.InfoLog("BOSSMAGIC_NATURE_PASS");
		}

		private unsafe static IEnumerator Run()
		{
			Application.runInBackground = true;
			while (!MagicSystem.RuneReady)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(3f);
			string text = "MagicTest_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
			PlayerProfile val = new PlayerProfile(text, (FileSource)2);
			val.SetName("Teste de Runas");
			AccessTools.Field(typeof(PlayerProfile), "m_firstSpawn").SetValue(val, false);
			Require(val.Save(), "fresh local profile saved");
			Game.SetProfile(text, (FileSource)2);
			string fullPath = Path.GetFullPath(Path.Combine(Paths.GameRootPath, "..", "evidence", "test-world.txt"));
			string text2 = (File.Exists(fullPath) ? File.ReadAllText(fullPath).Trim() : text);
			Require(text2.StartsWith("MagicTest_", StringComparison.Ordinal), "integration world has reserved name");
			File.WriteAllText(fullPath, text2);
			World createWorld = World.GetCreateWorld(text2, (FileSource)2);
			ZNet.SetServer(true, false, false, text, "", createWorld);
			ZNet.ResetServerHost();
			FejdStartup obj = Object.FindFirstObjectByType<FejdStartup>();
			AccessTools.Method(typeof(FejdStartup), "LoadMainScene", (Type[])null, (Type[])null).Invoke(obj, null);
			plugin.InfoLog("BOSSMAGIC_GAMEPLAY_WORLD " + text);
			while (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				yield return null;
			}
			Player player = Player.m_localPlayer;
			while (((Character)player).InCutscene() || ((Character)player).IsTeleporting())
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(2f);
			player.SetGodMode(true);
			TestArea.Reset(((Component)player).transform.position, 300f);
			if (Array.IndexOf(Environment.GetCommandLineArgs(), "-bossmagic-nature-test") >= 0)
			{
				IEnumerator natureTest = RunNature(player);
				while (natureTest.MoveNext())
				{
					yield return natureTest.Current;
				}
				TestArea.Reset(((Component)player).transform.position, 300f);
				RestoreTestConfig();
				plugin.InfoLog("BOSSMAGIC_GAMEPLAY_PASS: focused Blessing of Nature test only.");
				Application.Quit(0);
				yield break;
			}
			if (Array.IndexOf(Environment.GetCommandLineArgs(), "-bossmagic-network-test") >= 0)
			{
				IEnumerator natureTest = NetworkTest.Run(player);
				while (natureTest.MoveNext())
				{
					yield return natureTest.Current;
				}
				RestoreTestConfig();
				plugin.InfoLog("BOSSMAGIC_GAMEPLAY_PASS: network receiver test");
				Application.Quit(0);
				yield break;
			}
			BeaconEffects.Prepare();
			ImpactEffects.Prepare();
			Require(ImpactEffects.SparkSystems > 0 && ImpactEffects.ThunderClips > 0 && ImpactEffects.SledgeSystems > 0, "native stomp thunder, lightning particles and sledge wave resolved");
			Require(ImpactEffects.EffectsSafe, "native visual effects have no damage scripts or colliders");
			GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj2).name = "BossMagic_TestPlatform";
			obj2.GetComponent<Renderer>().sharedMaterial = new Material(Shader.Find("Sprites/Default"))
			{
				color = new Color(0.18f, 0.22f, 0.18f, 1f),
				renderQueue = 2000
			};
			obj2.layer = LayerMask.NameToLayer("static_solid");
			Vector3 origin = ((Component)player).transform.position + Vector3.up * 30f;
			obj2.transform.position = origin - Vector3.up;
			obj2.transform.localScale = new Vector3(24f, 1f, 24f);
			while (!((Character)player).TeleportTo(origin, Quaternion.identity, true))
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			while (((Character)player).IsTeleporting())
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(1f);
			Require(Vector3.Distance(((Component)player).transform.position, origin) < 2f, "player reached integration platform");
			Vector3 probeStart = ((Component)player).transform.position + Vector3.up * 60f;
			LightningMissile straightProbe = new GameObject("StraightProbe").AddComponent<LightningMissile>();
			LightningMissile arrowProbe = new GameObject("ArrowProbe").AddComponent<LightningMissile>();
			((Component)straightProbe).transform.position = probeStart;
			((Component)arrowProbe).transform.position = probeStart + Vector3.forward * 4f;
			straightProbe.Initialize(player, Vector3.right, MagicSystem.TrajectoryMode.Straight);
			arrowProbe.Initialize(player, Vector3.right, MagicSystem.TrajectoryMode.Arrow);
			yield return (object)new WaitForSeconds(0.5f);
			Require(Object.op_Implicit((Object)(object)straightProbe) && Mathf.Abs(((Component)straightProbe).transform.position.y - probeStart.y) < 0.01f, "Straight mode preserves height for a horizontal shot");
			float num = 0.5f * MagicSystem.Gravity.Value * arrowProbe.FlightTime * arrowProbe.FlightTime;
			float num2 = probeStart.y - ((Component)arrowProbe).transform.position.y;
			Require(Mathf.Abs(num2 - num) < 0.02f, "Arrow mode follows configured gravity");
			plugin.InfoLog("BOSSMAGIC_TRAJECTORY_TEST straightDrop=" + (probeStart.y - ((Component)straightProbe).transform.position.y) + " arrowDrop=" + num2 + " expected=" + num);
			Object.Destroy((Object)(object)((Component)straightProbe).gameObject);
			Object.Destroy((Object)(object)((Component)arrowProbe).gameObject);
			((Humanoid)player).GetInventory().RemoveAll();
			ItemData sword = Add(player, "SwordBronze", 0);
			ItemData shield = Add(player, "ShieldWood", 1);
			ItemData rune = Add(player, "BossMagic_LightningRune", 2);
			((Humanoid)player).EquipItem(sword, false);
			((Humanoid)player).EquipItem(shield, false);
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword && AccessTools.Field(typeof(Humanoid), "m_leftItem").GetValue(player) == shield, "sword and shield equipped");
			Vector3 impactPoint = origin + Vector3.forward * 7f - Vector3.up * 0.45f;
			Character enemy = Target(impactPoint + Vector3.right * 0.9f + Vector3.up * 0.2f, tamed: false);
			Character tame = Target(impactPoint - Vector3.right * 1.2f + Vector3.up * 0.2f, tamed: true);
			yield return (object)new WaitForSeconds(1f);
			Require(MagicSystem.IsTarget(enemy, player), "hostile target recognized");
			Require(!MagicSystem.IsTarget(tame, player), "tamed target excluded");
			MethodInfo useHotbar = AccessTools.Method(typeof(Player), "UseHotbarItem", (Type[])null, (Type[])null);
			((Character)player).AddStamina(100f);
			float stamina = player.GetStamina();
			float health = enemy.GetHealth();
			float tameHealth = tame.GetHealth();
			int casts = MagicSystem.CastCount;
			int impacts = MagicSystem.ImpactCount;
			int hits = MagicSystem.DamageCount;
			Vector3 enemyStart = ((Component)enemy).transform.position;
			Plugin obj3 = plugin;
			string[] obj4 = new string[8] { "BOSSMAGIC_ARENA origin=", null, null, null, null, null, null, null };
			Vector3 val2 = origin;
			obj4[1] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj4[2] = " player=";
			val2 = ((Component)player).transform.position;
			obj4[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj4[4] = " target=";
			val2 = enemy.GetCenterPoint();
			obj4[5] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj4[6] = " aim=";
			val2 = impactPoint;
			obj4[7] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj3.InfoLog(string.Concat(obj4));
			plugin.InfoLog("BOSSMAGIC_TARGET mass=" + ((Component)enemy).GetComponent<Rigidbody>().mass + " sleeping=" + enemy.GetBaseAI().IsSleeping());
			Aim(player, impactPoint);
			useHotbar.Invoke(player, new object[1] { 3 });
			Require(MagicSystem.CastCount == casts + 1, "hotbar slot 3 casts rune");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword && AccessTools.Field(typeof(Humanoid), "m_leftItem").GetValue(player) == shield, "casting preserves both equipped weapons");
			Require(((Humanoid)player).GetInventory().ContainsItem(rune) && rune.m_stack == 1, "rune is reusable and not consumed");
			Require(Mathf.Abs(stamina - player.GetStamina() - MagicSystem.Cost.Value) < 0.1f, "stamina cost applied exactly once");
			useHotbar.Invoke(player, new object[1] { 3 });
			Require(MagicSystem.CastCount == casts + 1, "cooldown blocks repeated hotbar use");
			yield return (object)new WaitForSeconds(0.4f);
			CaptureView();
			yield return (object)new WaitForSeconds(0.6f);
			Require(ImpactEffects.Plays > 0, "impact spawns the paired native effects");
			Require(MagicSystem.ImpactCount == impacts + 1, "projectile collides and explodes exactly once");
			Require(MagicSystem.DamageCount == hits + 1, "impact damages hostile target once despite multiple colliders");
			Require(enemy.GetHealth() < health, "electrical hit reduces enemy health");
			Require(Mathf.Abs(tame.GetHealth() - tameHealth) < 0.01f, "tamed creature takes no damage");
			val2 = Vector3.ProjectOnPlane(((Component)enemy).transform.position - enemyStart, Vector3.up);
			Require(((Vector3)(ref val2)).magnitude > 0.05f, "impact moves hostile target");
			plugin.InfoLog("BOSSMAGIC_GAMEPLAY_DAMAGE before=" + health + " after=" + enemy.GetHealth() + " displacement=" + Vector3.Distance(((Component)enemy).transform.position, enemyStart));
			MagicSystem.NextCast = 0f;
			((Character)player).UseStamina(player.GetStamina() + 10f);
			useHotbar.Invoke(player, new object[1] { 3 });
			Require(MagicSystem.CastCount == casts + 1, "insufficient stamina blocks casting");
			GameObject wall = GameObject.CreatePrimitive((PrimitiveType)3);
			wall.layer = LayerMask.NameToLayer("static_solid");
			wall.transform.position = origin + Vector3.forward * 3f + Vector3.up;
			wall.transform.localScale = new Vector3(12f, 8f, 0.4f);
			((Component)enemy).transform.position = origin + Vector3.forward * 4f;
			((Component)tame).transform.position = origin + Vector3.right * 9f;
			Physics.SyncTransforms();
			health = enemy.GetHealth();
			hits = MagicSystem.DamageCount;
			MagicSystem.Impact(player, origin + Vector3.forward * 2f, Vector3.up, 25f, 3f, 5f);
			yield return (object)new WaitForSeconds(0.2f);
			Require(MagicSystem.DamageCount == hits && Mathf.Abs(enemy.GetHealth() - health) < 0.01f, "solid wall blocks area damage");
			Object.Destroy((Object)(object)wall);
			yield return (object)new WaitForSeconds(8f);
			Require(SurgeSystem.Ready, "Surge registered");
			ItemData surge = Add(player, "BossMagic_SurgeRune", 3);
			((Character)player).AddStamina(200f);
			float normalSpeed = (float)AccessTools.Method(typeof(Player), "GetRunSpeedFactor", (Type[])null, (Type[])null).Invoke(player, null);
			stamina = player.GetStamina();
			useHotbar.Invoke(player, new object[1] { 4 });
			Require(SurgeSystem.Active, "Surge activates through hotbar");
			Require(Mathf.Abs(stamina - player.GetStamina() - SurgeSystem.Cost.Value) < 0.1f, "Surge charges activation once");
			Require(Mathf.Abs((float)AccessTools.Method(typeof(Player), "GetRunSpeedFactor", (Type[])null, (Type[])null).Invoke(player, null) - normalSpeed * SurgeSystem.Multiplier.Value) < 0.01f, "Surge increases running speed");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword && AccessTools.Field(typeof(Humanoid), "m_leftItem").GetValue(player) == shield, "Surge preserves sword and shield");
			Require(((Humanoid)player).GetInventory().ContainsItem(surge), "Surge rune remains in inventory");
			float num3 = 10f;
			((Character)player).GetSEMan().ModifyRunStaminaDrain(10f, ref num3, Vector3.forward, true);
			Require(num3 == 0f, "ActivationOnly removes normal sprint drain");
			float stamina2 = player.GetStamina();
			useHotbar.Invoke(player, new object[1] { 4 });
			Require(player.GetStamina() == stamina2, "Surge cannot stack or charge twice");
			Require(SurgeSystem.Aura.GetComponentsInChildren<ParticleSystem>().Length != 0 && SurgeSystem.Aura.GetComponentsInChildren<Collider>().Length == 0, "electrical aura is visual only");
			yield return (object)new WaitForSeconds(1f);
			CaptureView("surge-native.png");
			yield return (object)new WaitForSeconds(SurgeSystem.Duration.Value + 0.2f);
			Require(!SurgeSystem.Active && Mathf.Abs((float)AccessTools.Method(typeof(Player), "GetRunSpeedFactor", (Type[])null, (Type[])null).Invoke(player, null) - normalSpeed) < 0.01f, "Surge expires and restores speed");
			num3 = 10f;
			((Character)player).GetSEMan().ModifyRunStaminaDrain(10f, ref num3, Vector3.forward, true);
			Require(num3 > 0f, "normal stamina drain restored");
			SurgeSystem.StaminaMode value = SurgeSystem.Mode.Value;
			bool saveOnConfigSet = ((BaseUnityPlugin)plugin).Config.SaveOnConfigSet;
			((BaseUnityPlugin)plugin).Config.SaveOnConfigSet = false;
			try
			{
				SurgeSystem.Mode.Value = SurgeSystem.StaminaMode.AdditionalSprintDrain;
				SurgeSystem.NextCast = 0f;
				((Character)player).AddStamina(200f);
				Require(SurgeSystem.TryCast(player), "additional drain mode activates");
			}
			finally
			{
				SurgeSystem.Mode.Value = value;
				((BaseUnityPlugin)plugin).Config.SaveOnConfigSet = saveOnConfigSet;
			}
			float num4 = 10f;
			((Character)player).GetSEMan().ModifyRunStaminaDrain(10f, ref num4, Vector3.forward, true);
			Require(Mathf.Abs(num4 - num3 - SurgeSystem.ExtraDrain.Value) < 0.01f, "additional drain adds to normal sprint cost");
			((Character)player).UseStamina(player.GetStamina() + 10f);
			yield return null;
			yield return null;
			Require(!SurgeSystem.Active, "continuous mode ends when stamina runs out");
			plugin.InfoLog("BOSSMAGIC_SURGE_PASS: hotbar, equipment, activation cost, speed, free sprint, duration, aura, additional drain, depletion, cleanup.");
			Require(BeaconSystem.Ready && BeaconEffects.Safe && BeaconEffects.ParticleCount > 0 && BeaconEffects.AudioCount > 0, "Beacon rune and harmless Obliterator audiovisuals ready");
			ItemData beacon = Add(player, "BossMagic_BeaconRune", 7);
			((Component)enemy).transform.position = origin + Vector3.forward * 7f;
			enemy.SetHealth(1000f);
			((Component)tame).transform.position = origin + Vector3.right * 9f;
			yield return (object)new WaitForSeconds(0.3f);
			Physics.SyncTransforms();
			((Character)player).AddStamina(200f);
			Aim(player, enemy.GetCenterPoint());
			Require((Object)(object)BeaconSystem.FindTarget(player, out var reason) == (Object)(object)enemy, "Beacon selects enemy directly under crosshair: " + reason);
			health = enemy.GetHealth();
			stamina = player.GetStamina();
			int castCount = BeaconSystem.CastCount;
			useHotbar.Invoke(player, new object[1] { 8 });
			Require(BeaconSystem.CastCount == castCount + 1, "Beacon casts through hotbar");
			Require(Mathf.Abs(health - enemy.GetHealth() - BeaconSystem.Damage.Value) < 0.1f, "Beacon deals configured pure base damage");
			Require(Mathf.Abs(stamina - player.GetStamina() - BeaconSystem.Cost.Value) < 0.1f, "Beacon charges stamina once");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword && AccessTools.Field(typeof(Humanoid), "m_leftItem").GetValue(player) == shield && ((Humanoid)player).GetInventory().ContainsItem(beacon), "Beacon preserves weapons and reusable rune");
			useHotbar.Invoke(player, new object[1] { 8 });
			Require(BeaconSystem.CastCount == castCount + 1, "Beacon cooldown prevents duplicate strike");
			yield return (object)new WaitForSeconds(0.08f);
			CaptureView("beacon-strike.png");
			FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "m_damageModifiers");
			DamageModifiers val3 = (DamageModifiers)fieldInfo.GetValue(enemy);
			DamageModifiers val4 = val3;
			val4.m_lightning = (DamageModifier)3;
			fieldInfo.SetValue(enemy, val4);
			enemy.SetHealth(1000f);
			BeaconSystem.ApplyPureHit(player, enemy, 100f);
			Require(Mathf.Abs(enemy.GetHealth() - 900f) < 0.1f, "pure hit ignores lightning immunity");
			val4.m_lightning = (DamageModifier)6;
			fieldInfo.SetValue(enemy, val4);
			enemy.SetHealth(1000f);
			BeaconSystem.ApplyPureHit(player, enemy, 100f);
			Require(Mathf.Abs(enemy.GetHealth() - 900f) < 0.1f, "pure hit ignores lightning vulnerability");
			HitData obj5 = BeaconSystem.MakeHit(player, enemy, 100f);
			obj5.ApplyArmor(10000f);
			Require(obj5.m_damage.m_damage == 100f, "pure component survives armor calculation");
			BeaconTestModifier beaconTestModifier = ScriptableObject.CreateInstance<BeaconTestModifier>();
			((Object)beaconTestModifier).name = "BossMagic_BeaconTestReduction";
			beaconTestModifier.Factor = 0.7f;
			((StatusEffect)beaconTestModifier).m_ttl = 30f;
			StatusEffect val5 = enemy.GetSEMan().AddStatusEffect((StatusEffect)(object)beaconTestModifier, false, 0, 0f, (short)0);
			Require((Object)(object)val5 != (Object)null, "test damage reduction registered through normal status system");
			enemy.SetHealth(1000f);
			BeaconSystem.ApplyPureHit(player, enemy, 100f);
			Require(Mathf.Abs(enemy.GetHealth() - 930f) < 0.1f, "100 pure damage respects general 30 percent reduction");
			((BeaconTestModifier)(object)val5).Factor = 1.2f;
			enemy.SetHealth(1000f);
			BeaconSystem.ApplyPureHit(player, enemy, 100f);
			Require(Mathf.Abs(enemy.GetHealth() - 880f) < 0.1f, "100 pure damage respects general 20 percent amplification");
			((BeaconTestModifier)(object)val5).Factor = 0f;
			enemy.SetHealth(1000f);
			BeaconSystem.ApplyPureHit(player, enemy, 100f);
			Require(Mathf.Abs(enemy.GetHealth() - 1000f) < 0.1f, "general complete damage prevention remains effective");
			enemy.GetSEMan().RemoveStatusEffect(val5, true);
			Object.Destroy((Object)(object)beaconTestModifier);
			fieldInfo.SetValue(enemy, val3);
			HitData val6 = new HitData(100f);
			val6.ApplyModifier(0.7f);
			Require(val6.m_damage.m_damage == 100f, "Beacon modifier patch leaves unrelated generic damage untouched");
			BeaconSystem.NextCast = 0f;
			((Character)player).UseStamina(player.GetStamina() + 10f);
			Aim(player, enemy.GetCenterPoint());
			Require(!BeaconSystem.TryCast(player), "Beacon cannot cast without stamina");
			((Character)player).AddStamina(200f);
			stamina = player.GetStamina();
			Aim(player, ((Character)player).GetEyePoint() + Vector3.up * 20f);
			Require(!BeaconSystem.TryCast(player) && player.GetStamina() == stamina, "missing target does not spend stamina");
			Aim(player, tame.GetCenterPoint());
			Require(!BeaconSystem.TryCast(player), "Beacon refuses tamed creatures");
			GameObject obj6 = GameObject.CreatePrimitive((PrimitiveType)3);
			obj6.layer = LayerMask.NameToLayer("static_solid");
			obj6.transform.position = origin + Vector3.forward * 4f + Vector3.up;
			obj6.transform.localScale = new Vector3(8f, 8f, 0.5f);
			Physics.SyncTransforms();
			Aim(player, enemy.GetCenterPoint());
			Require(!BeaconSystem.TryCast(player), "wall blocks Beacon targeting");
			obj6.transform.position = enemy.GetCenterPoint() + Vector3.up * 3f;
			obj6.transform.localScale = new Vector3(5f, 0.5f, 5f);
			Physics.SyncTransforms();
			Aim(player, enemy.GetCenterPoint());
			Require(!BeaconSystem.TryCast(player), "roof blocks incoming Beacon");
			Object.Destroy((Object)(object)obj6);
			Require(RuneBag.Accepts(beacon), "default rune bag accepts Beacon");
			plugin.InfoLog("BOSSMAGIC_BEACON_PASS: native ray, hotbar, equipment, reuse, pure damage, armor, immunity, vulnerability, general modifiers, cooldown, stamina, empty aim, tamed, walls, roof, bag.");
			Require(RuneBag.Ready, "rune bag registered");
			yield return (object)new WaitForSeconds(8f);
			Require(WindScar.Ready, "Wind Scar registered");
			((Humanoid)player).GetInventory().RemoveItem(beacon);
			ItemData wind = Add(player, "BossMagic_WindScarRune", 7);
			((Component)enemy).transform.position = origin + Vector3.forward * 7f;
			enemy.SetHealth(1000f);
			Physics.SyncTransforms();
			Aim(player, enemy.GetCenterPoint());
			((Character)player).AddStamina(200f);
			int castCount2 = WindScar.CastCount;
			int windHits = WindScar.Hits;
			stamina = player.GetStamina();
			health = enemy.GetHealth();
			useHotbar.Invoke(player, new object[1] { 8 });
			Require(WindScar.CastCount == castCount2 + 1 && Mathf.Abs(stamina - player.GetStamina() - WindScar.Cost.Value) < 0.1f, "Wind Scar hotbar activation charges once");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == sword && AccessTools.Field(typeof(Humanoid), "m_leftItem").GetValue(player) == shield && ((Humanoid)player).GetInventory().ContainsItem(wind), "Wind Scar preserves weapons and reusable rune");
			useHotbar.Invoke(player, new object[1] { 8 });
			Require(WindScar.CastCount == castCount2 + 1, "Wind Scar cooldown prevents repeat cast");
			yield return (object)new WaitForSeconds(0.12f);
			CaptureView("wind-scar.png");
			yield return (object)new WaitForSeconds(0.7f);
			Require(Mathf.Abs(health - enemy.GetHealth() - WindScar.Slash.Value) < 0.1f && WindScar.Hits == windHits + 1, "Wind Scar projectile deals Slash exactly once");
			Vector3 windProbeStart = origin + Vector3.up * 60f;
			WindProjectile windProbe = WindScar.Launch(player, windProbeStart, Vector3.right);
			yield return (object)new WaitForSeconds(0.4f);
			Require(Object.op_Implicit((Object)(object)windProbe) && Mathf.Abs(((Component)windProbe).transform.position.y - windProbeStart.y) < 0.01f && ((Component)windProbe).transform.position.x > windProbeStart.x + 1f, "Wind Scar flies straight without gravity");
			Object.Destroy((Object)(object)((Component)windProbe).gameObject);
			GameObject treeObject = Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("Beech1"), origin + Vector3.right * 40f, Quaternion.identity);
			woodFixtures.Add(treeObject);
			TreeBase tree = treeObject.GetComponent<TreeBase>();
			ZDO treeData = treeObject.GetComponent<ZNetView>().GetZDO();
			treeData.Set(ZDOVars.s_health, 1000f);
			Physics.SyncTransforms();
			Vector3 treeAim = treeObject.transform.position + Vector3.up;
			WindScar.Launch(player, treeAim - Vector3.forward * 5f, Vector3.forward);
			yield return (object)new WaitForSeconds(0.6f);
			Require(Mathf.Abs(treeData.GetFloat(ZDOVars.s_health, 1000f) - (1000f - WindScar.Woodcut.Value)) < 0.1f, "Wind Scar projectile applies high woodcut damage to real tree");
			Collider collider = ((Component)tree).GetComponentsInChildren<Collider>().First();
			AccessTools.Field(typeof(TreeBase), "m_minToolTier").SetValue(tree, 4);
			float num5 = treeData.GetFloat(ZDOVars.s_health, 1000f);
			WindScar.Impact(player, collider, treeAim, Vector3.forward, 40f, 200f, 0);
			Require(treeData.GetFloat(ZDOVars.s_health, 1000f) == num5, "Wind Scar respects tree tool-tier requirement");
			string[] array = new string[2] { "m_logPrefab", "m_stubPrefab" };
			foreach (string field in array)
			{
				GameObject val7 = (GameObject)AccessTools.Field(typeof(TreeBase), field).GetValue(tree);
				GameObject woodObject = Object.Instantiate<GameObject>(val7, origin + Vector3.right * 45f, Quaternion.identity);
				woodFixtures.Add(woodObject);
				ZDO woodData = woodObject.GetComponent<ZNetView>().GetZDO();
				woodData.Set(ZDOVars.s_health, 1000f);
				yield return (object)new WaitForSeconds(0.3f);
				Collider collider2 = woodObject.GetComponentsInChildren<Collider>().First();
				WindScar.Impact(player, collider2, woodObject.transform.position, Vector3.forward, 40f, 200f, 3);
				Require(woodData.GetFloat(ZDOVars.s_health, 1000f) < 1000f, "Wind Scar cuts wood component " + field);
				ZNetScene.instance.Destroy(woodObject);
			}
			ZNetScene.instance.Destroy(treeObject);
			woodFixtures.Clear();
			GameObject testWall = GameObject.CreatePrimitive((PrimitiveType)3);
			testWall.layer = LayerMask.NameToLayer("static_solid");
			testWall.transform.position = origin + Vector3.forward * 4f + Vector3.up;
			testWall.transform.localScale = new Vector3(8f, 8f, 0.5f);
			Physics.SyncTransforms();
			health = enemy.GetHealth();
			Player player2 = player;
			Vector3 eyePoint = ((Character)player).GetEyePoint();
			val2 = enemy.GetCenterPoint() - ((Character)player).GetEyePoint();
			WindScar.Launch(player2, eyePoint, ((Vector3)(ref val2)).normalized);
			yield return (object)new WaitForSeconds(0.6f);
			Require(enemy.GetHealth() == health, "solid wall stops Wind Scar before enemy");
			Object.Destroy((Object)(object)testWall);
			health = tame.GetHealth();
			WindScar.Impact(player, ((Component)tame).GetComponentsInChildren<Collider>().First(), tame.GetCenterPoint(), Vector3.forward, 40f, 200f, 3);
			Require(tame.GetHealth() == health, "Wind Scar does not damage allied creatures");
			WindScar.NextCast = 0f;
			((Character)player).UseStamina(player.GetStamina() + 10f);
			Require(!WindScar.TryCast(player), "Wind Scar refuses casting without stamina");
			Require(RuneBag.Accepts(wind), "default bag accepts Wind Scar");
			plugin.InfoLog("BOSSMAGIC_WIND_PASS: hotbar, equipment, cost, cooldown, slash hit, straight trajectory, tree/log/stump woodcut, tool tier, wall, allies, stamina, bag.");
			ItemData bag = RuneBag.Give(player);
			bag.m_gridPos = new Vector2i(4, 0);
			useHotbar.Invoke(player, new object[1] { 5 });
			yield return (object)new WaitForSeconds(0.3f);
			Require(RuneBag.OpenItem == bag && InventoryGui.instance.IsContainerOpen(), "bag opens native container UI from hotbar");
			Require(RuneBag.View.GetInventory() == RuneBag.Contents && RuneBag.View.IsOwner(), "native container uses portable inventory");
			InventoryGrid val8 = (InventoryGrid)AccessTools.Field(typeof(InventoryGui), "m_containerGrid").GetValue(InventoryGui.instance);
			InventoryGrid val9 = (InventoryGrid)AccessTools.Field(typeof(InventoryGui), "m_playerGrid").GetValue(InventoryGui.instance);
			Require(val8.DropItem(((Humanoid)player).GetInventory(), rune, 1, new Vector2i(0, 0)), "native drag deposits lightning rune");
			Require(!((Humanoid)player).GetInventory().ContainsItem(rune) && RuneBag.Contents.GetAllItems().Count == 1, "deposit removes original and stores one rune");
			Require(!val8.DropItem(((Humanoid)player).GetInventory(), sword, 1, new Vector2i(0, 0)), "invalid swap into bag rejected before mutation");
			ItemData val10 = RuneBag.Contents.GetItemAt(0, 0);
			Require(!val9.DropItem(RuneBag.Contents, val10, 1, sword.m_gridPos), "reverse swap cannot smuggle a sword into bag");
			Require(((Humanoid)player).GetInventory().ContainsItem(sword) && RuneBag.Contents.GetAllItems().Count == 1, "rejected swaps preserve both inventories");
			Require(!val8.DropItem(((Humanoid)player).GetInventory(), bag, 1, new Vector2i(1, 0)), "bag cannot contain itself");
			RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), surge);
			Require(!((Humanoid)player).GetInventory().ContainsItem(surge) && RuneBag.Contents.GetAllItems().Count == 2, "quick transfer deposits Surge");
			val10.m_customData["BossMagic.TestMarker"] = "preserve-me";
			RuneBag.Close();
			ZPackage val11 = new ZPackage();
			((Humanoid)player).GetInventory().Save(val11);
			Inventory val12 = new Inventory("PersistenceProbe", (Sprite)null, 8, 4);
			val12.Load(new ZPackage(val11.GetBase64()));
			Inventory val13 = RuneBag.Read(val12.GetAllItems().Single(RuneBag.IsBag));
			Require(val13.GetAllItems().Count == 2 && val13.GetAllItems().Any((ItemData val26) => val26.m_customData.TryGetValue("BossMagic.TestMarker", out var value3) && value3 == "preserve-me"), "character inventory roundtrip preserves contents and rune metadata");
			Require(RuneBag.Read(RuneBag.Give(player)).GetAllItems().Count == 0, "second bag has independent empty storage");
			Require(RuneBag.Open(player, bag), "bag reopens with saved contents");
			string value2 = RuneBag.AcceptedPrefabs.Value;
			bool saveOnConfigSet2 = ((BaseUnityPlugin)plugin).Config.SaveOnConfigSet;
			((BaseUnityPlugin)plugin).Config.SaveOnConfigSet = false;
			try
			{
				RuneBag.AcceptedPrefabs.Value = "Stone";
				val10 = RuneBag.Contents.GetAllItems().First((ItemData val26) => ((Object)val26.m_dropPrefab).name == "BossMagic_LightningRune");
				((Humanoid)player).GetInventory().MoveItemToThis(RuneBag.Contents, val10);
				Require(((Humanoid)player).GetInventory().ContainsItem(val10), "removed prefab can still be withdrawn");
				RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), val10);
				Require(((Humanoid)player).GetInventory().ContainsItem(val10), "removed prefab cannot be deposited again");
				ItemData val14 = Add(player, "Stone", 6);
				RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), val14);
				Require(RuneBag.Contents.GetAllItems().Any((ItemData val26) => ((Object)val26.m_dropPrefab).name == "Stone"), "allowlist changes accept another prefab immediately");
				((Humanoid)player).GetInventory().MoveItemToThis(RuneBag.Contents, RuneBag.Contents.GetAllItems().First((ItemData val26) => ((Object)val26.m_dropPrefab).name == "Stone"));
			}
			finally
			{
				RuneBag.AcceptedPrefabs.Value = value2;
				((BaseUnityPlugin)plugin).Config.SaveOnConfigSet = saveOnConfigSet2;
			}
			RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), val10);
			for (int num6 = RuneBag.Contents.GetAllItems().Count; num6 < 8; num6++)
			{
				ItemData val15 = MagicSystem.GiveRune(player);
				RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), val15);
			}
			ItemData val16 = MagicSystem.GiveRune(player);
			RuneBag.Contents.MoveItemToThis(((Humanoid)player).GetInventory(), val16);
			Require(RuneBag.Contents.GetAllItems().Count == 8 && ((Humanoid)player).GetInventory().ContainsItem(val16), "full bag rejects ninth rune without loss");
			ItemDrop[] previousDrops = Object.FindObjectsByType<ItemDrop>((FindObjectsSortMode)0);
			Require(((Humanoid)player).DropItem(((Humanoid)player).GetInventory(), bag, 1), "filled bag can be dropped");
			Require(RuneBag.OpenItem == null, "moving open bag closes the container safely");
			ItemDrop val17 = Object.FindObjectsByType<ItemDrop>((FindObjectsSortMode)0).First((ItemDrop d) => !previousDrops.Contains(d) && RuneBag.IsBag(d.m_itemData) && d.m_itemData.m_customData.ContainsKey("BossMagic.RuneBag.v1"));
			Require(RuneBag.Read(val17.m_itemData).GetAllItems().Count == 8, "world drop keeps all eight runes");
			AccessTools.Method(typeof(ItemDrop), "Save", (Type[])null, (Type[])null).Invoke(val17, null);
			val17.m_itemData.m_customData.Clear();
			AccessTools.Method(typeof(ItemDrop), "Load", (Type[])null, (Type[])null).Invoke(val17, null);
			Require(RuneBag.Read(val17.m_itemData).GetAllItems().Count == 8, "world item serialization preserves bag contents");
			Require(((Humanoid)player).Pickup(((Component)val17).gameObject, false, false), "filled bag can be picked up again");
			bag = ((Humanoid)player).GetInventory().GetAllItems().First((ItemData val26) => RuneBag.IsBag(val26) && val26.m_customData.ContainsKey("BossMagic.RuneBag.v1"));
			Require(RuneBag.Open(player, bag), "picked up bag reopens");
			yield return (object)new WaitForSeconds(0.3f);
			AccessTools.Method(typeof(InventoryGui), "OnTakeAll", (Type[])null, (Type[])null).Invoke(InventoryGui.instance, null);
			Require(RuneBag.Contents.GetAllItems().Count == 0, "native Take All retrieves bag contents");
			RuneBag.Close();
			string text3 = bag.m_customData["BossMagic.RuneBag.v1"];
			bag.m_customData["BossMagic.RuneBag.prefabs.v1"] = "BossMagic_MissingDependency_Test";
			bool flag = false;
			try
			{
				RuneBag.Read(bag);
			}
			catch (InvalidOperationException)
			{
				flag = true;
			}
			Require(flag && bag.m_customData["BossMagic.RuneBag.v1"] == text3, "missing prefab blocks loading without rewriting stored contents");
			bag.m_customData["BossMagic.RuneBag.prefabs.v1"] = "";
			plugin.InfoLog("BOSSMAGIC_BAG_PASS: native UI, drag, quick transfer, filtering, swaps, nesting, capacity, per-item persistence, world drop/load/pickup, take all, missing dependencies.");
			ItemData val18 = LightningChain.Give(player);
			Require(val18 != null && RuneBag.Accepts(val18), "Chain rune registered and accepted by bag");
			Character chainTarget = Target(((Component)player).transform.position + Vector3.right * 6f, tamed: false);
			Character chainExtraA = Target(((Component)chainTarget).transform.position + Vector3.forward * 1.5f, tamed: false);
			Character chainExtraB = Target(((Component)chainTarget).transform.position - Vector3.forward * 1.5f, tamed: false);
			yield return (object)new WaitForSeconds(0.3f);
			((Character)player).AddStamina(200f);
			LightningChain.NextCast = 0f;
			Aim(player, chainTarget.GetCenterPoint());
			object heldRight = AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player);
			Require(LightningChain.TryCast(player) && (Object)(object)LightningChain.Target == (Object)(object)chainTarget, "Chain captures aimed creature");
			Require(LightningChain.IsLinked(chainExtraA) && LightningChain.IsLinked(chainExtraB) && LightningChain.TargetCount <= LightningChain.MaxTargets.Value, "Chain captures nearby secondary enemies within limit");
			Vector3 extraStartA = ((Component)chainExtraA).transform.position;
			Vector3 extraStartB = ((Component)chainExtraB).transform.position;
			Vector3 chainStart = ((Component)chainTarget).transform.position;
			float chainHealth = chainTarget.GetHealth();
			yield return (object)new WaitForSeconds(0.7f);
			Require(Vector3.Distance(chainStart, ((Component)chainTarget).transform.position) > 0.5f, "Chain physically drags creature toward leash range");
			Require(Vector3.Distance(extraStartA, ((Component)chainExtraA).transform.position) > 0.5f && Vector3.Distance(extraStartB, ((Component)chainExtraB).transform.position) > 0.5f, "Chain pulls all secondary targets");
			Require(chainTarget.GetHealth() == chainHealth && AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == heldRight, "Chain keeps weapons and does not damage target");
			((Component)Camera.main).transform.position = ((Character)player).GetCenterPoint() + Vector3.back * 7f + Vector3.up * 3f;
			((Component)Camera.main).transform.rotation = Quaternion.LookRotation((((Character)player).GetCenterPoint() + chainTarget.GetCenterPoint()) * 0.5f - ((Component)Camera.main).transform.position);
			RuneHotbarTest.Capture("lightning-chain.png");
			Require(LightningChain.TryCast(player) && !Object.op_Implicit((Object)(object)LightningChain.Target), "Chain reactivation releases target during cooldown");
			Require(LightningChain.TargetCount == 0, "Chain cancellation releases every target");
			ZNetScene.instance.Destroy(((Component)chainExtraA).gameObject);
			ZNetScene.instance.Destroy(((Component)chainExtraB).gameObject);
			Require(!LightningChain.ValidTarget(tame, player) && !LightningChain.ValidTarget((Character)(object)player, player), "Chain excludes allies and player");
			LightningChain.NextCast = 0f;
			Aim(player, chainTarget.GetCenterPoint());
			Require(LightningChain.TryCast(player), "Chain can reacquire released creature");
			GameObject obj7 = GameObject.CreatePrimitive((PrimitiveType)3);
			obj7.layer = LayerMask.NameToLayer("Default");
			obj7.transform.position = (chainTarget.GetCenterPoint() + ((Character)player).GetCenterPoint()) * 0.5f;
			obj7.transform.localScale = new Vector3(0.3f, 4f, 4f);
			Physics.SyncTransforms();
			LightningChain.Tick();
			Require(!Object.op_Implicit((Object)(object)LightningChain.Target), "Chain breaks when solid obstacle blocks tether");
			Object.Destroy((Object)(object)obj7);
			yield return null;
			LightningChain.NextCast = 0f;
			Aim(player, chainTarget.GetCenterPoint());
			Require(LightningChain.TryCast(player), "Chain reacquires after obstacle removed");
			((Component)chainTarget).transform.position = ((Component)player).transform.position + Vector3.right * (LightningChain.Range.Value + 3f);
			Physics.SyncTransforms();
			LightningChain.Tick();
			Require(!Object.op_Implicit((Object)(object)LightningChain.Target), "Chain breaks beyond maximum range");
			((Component)chainTarget).transform.position = ((Component)player).transform.position + Vector3.right * 5f;
			Physics.SyncTransforms();
			LightningChain.NextCast = 0f;
			Aim(player, chainTarget.GetCenterPoint());
			((Character)player).AddStamina(200f);
			float originalDuration = LightningChain.Duration.Value;
			LightningChain.Duration.Value = 1f;
			Require(LightningChain.TryCast(player), "Chain starts duration probe");
			yield return (object)new WaitForSeconds(1.2f);
			Require(!Object.op_Implicit((Object)(object)LightningChain.Target), "Chain expires and releases creature");
			LightningChain.Duration.Value = originalDuration;
			ZNetScene.instance.Destroy(((Component)chainTarget).gameObject);
			plugin.InfoLog("BOSSMAGIC_CHAIN_PASS: targeting, physics drag, release, equipment, no damage, ally exclusion, wall and distance break.");
			ItemData val19 = RootCage.Give(player);
			Require(val19 != null && RuneBag.Accepts(val19), "Root Cage rune registered and accepted by bag");
			Vector3 candidate = ((Component)player).transform.position + Vector3.left * 5f;
			RootCage.NextCast = 0f;
			((Character)player).AddStamina(200f);
			float stamina3 = player.GetStamina();
			Require(RootCage.TryCast(player) && RootCage.Selecting && player.GetStamina() == stamina3, "Root Cage enters selection without charging");
			RootCage.Cancel();
			Require(!RootCage.Selecting && player.GetStamina() == stamina3, "Root Cage cancellation is free");
			Require(RootCage.TryCast(player), "Root Cage selection restarts");
			Require(!RootCage.Confirm(((Component)player).transform.position + Vector3.up * 100f) && player.GetStamina() == stamina3, "Root Cage rejects invalid placement without cost");
			Require(RootCage.GroundArea(player, candidate, out var cageGround, out var _), "Root Cage validates supported circular area");
			Cursor.visible = false;
			Cursor.lockState = (CursorLockMode)1;
			Aim(player, cageGround);
			RootCage.Tick();
			Require(RootCage.Selecting && !(bool)AccessTools.Method(typeof(RootCage), "AttackInput", (Type[])null, (Type[])null).Invoke(null, new object[1] { player }), "Root Cage preview reserves attack input");
			RuneHotbarTest.Capture("root-cage-preview.png");
			Require(RootCage.Confirm(cageGround) && !RootCage.Selecting && RootCage.Roots.Count == RootCage.SegmentCount, "Root Cage creates native root ring on confirmation");
			Require(player.GetStamina() < stamina3 && RootCage.NextCast > Time.time, "Root Cage charges stamina and cooldown only on confirmation");
			yield return (object)new WaitForSeconds(0.6f);
			CageRoot cageRoot = RootCage.Roots[0];
			Require(((Component)cageRoot).GetComponentsInChildren<MeshRenderer>().Any(delegate(MeshRenderer r)
			{
				//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_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				if (((Renderer)r).enabled)
				{
					Bounds bounds = ((Renderer)r).bounds;
					if (((Bounds)(ref bounds)).size.y > 1f)
					{
						bounds = ((Renderer)r).bounds;
						return ((Bounds)(ref bounds)).size.y < 6f;
					}
				}
				return false;
			}), "Root Cage animated root remains visible at body height");
			foreach (CageRoot item in RootCage.Roots.Take(1))
			{
				Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>();
				foreach (Renderer val20 in componentsInChildren)
				{
					Plugin obj8 = plugin;
					string[] obj9 = new string[12]
					{
						"CAGE_RENDER_PROBE ",
						((object)val20).GetType().Name,
						" enabled=",
						val20.enabled.ToString(),
						" bounds=",
						((object)val20.bounds/*cast due to .constrained prefix*/).ToString(),
						" root=",
						null,
						null,
						null,
						null,
						null
					};
					val2 = ((Component)item).transform.position;
					obj9[7] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
					obj9[8] = " visual=";
					val2 = item.Visual.position;
					obj9[9] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
					obj9[10] = " scale=";
					val2 = item.Visual.localScale;
					obj9[11] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
					obj8.InfoLog(string.Concat(obj9));
				}
			}
			RaycastHit val22 = default(RaycastHit);
			for (int num8 = 0; num8 < RootCage.Roots.Count; num8++)
			{
				Vector3 val21 = (((Component)RootCage.Roots[num8]).transform.position + ((Component)RootCage.Roots[(num8 + 1) % RootCage.Roots.Count]).transform.position) * 0.5f - cageGround;
				val21.y = 0f;
				Require(Physics.SphereCast(cageGround + Vector3.up * 1.5f, 0.25f, ((Vector3)(ref val21)).normalized, ref val22, RootCage.Radius.Value + 1f, MagicSystem.WorldMask) && Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val22)).collider).GetComponent<CageRoot>()), "Root Cage adjacent root bodies close passage " + num8);
			}
			Require(RootCage.Roots.All((CageRoot r) => Object.op_Implicit((Object)(object)((Component)r).GetComponent<CapsuleCollider>()) && !Object.op_Implicit((Object)(object)((Component)r).GetComponent<BoxCollider>())), "Root Cage uses individual root bodies, no wall panels");
			Character cageEnemy = Target(cageGround + Vector3.up * 0.2f, tamed: false);
			Character cageAlly = Target(cageGround + Vector3.up * 0.2f + Vector3.forward, tamed: true);
			float enemyHealthBefore = cageEnemy.GetHealth();
			float allyHealthBefore = cageAlly.GetHealth();
			Require(RootCage.Roots.All((CageRoot r) => !r.CanHit((Character)(object)player) && !r.CanHit(cageAlly)), "Root Cage rejects player and allies as attack targets");
			yield return (object)new WaitForSeconds(3.5f);
			Require(cageEnemy.GetHealth() < enemyHealthBefore && RootCage.Roots.Count((CageRoot r) => r.Hits > 0) >= 2, "Root Cage individual roots animate and damage nearby enemy");
			Require(cageAlly.GetHealth() == allyHealthBefore, "Root Cage attacks preserve allied creature health");
			ZNetScene.instance.Destroy(((Component)cageEnemy).gameObject);
			ZNetScene.instance.Destroy(((Component)cageAlly).gameObject);
			Require(((Component)cageRoot).GetComponentsInChildren<Character>().Length == 0 && ((Component)cageRoot).GetComponentsInChildren<ZNetView>().Length == 0 && ((Component)cageRoot).GetComponentsInChildren<Renderer>().Length != 0, "Root Cage native visuals contain no enemy or network behaviour");
			Vector3 towardsRoot = ((Component)cageRoot).transform.position - cageGround;
			towardsRoot.y = 0f;
			RaycastHit val23 = default(RaycastHit);
			Require(Physics.Raycast(cageGround + Vector3.up * 1.5f, ((Vector3)(ref towardsRoot)).normalized, ref val23, RootCage.Radius.Value + 2f, MagicSystem.WorldMask) && Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val23)).collider).GetComponent<CageRoot>()), "Root Cage collision blocks exit across ring");
			((Component)Camera.main).transform.position = cageGround + Vector3.back * 12f + Vector3.up * 9f;
			((Component)Camera.main).transform.rotation = Quaternion.LookRotation(cageGround + Vector3.up - ((Component)Camera.main).transform.position);
			RuneHotbarTest.Capture("root-cage.png");
			GameObject collisionProbe = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)collisionProbe).name = "CageCollisionProbe";
			collisionProbe.transform.localScale = Vector3.one * 0.5f;
			collisionProbe.transform.position = cageGround + Vector3.up * 1.5f + ((Vector3)(ref towardsRoot)).normalized * (RootCage.Radius.Value - 1.2f);
			Rigidbody probeBody = collisionProbe.AddComponent<Rigidbody>();
			probeBody.useGravity = false;
			probeBody.linearVelocity = ((Vector3)(ref towardsRoot)).normalized * 8f;
			yield return (object)new WaitForSeconds(0.35f);
			Require(Vector3.Dot(collisionProbe.transform.position - cageGround, ((Vector3)(ref towardsRoot)).normalized) < RootCage.Radius.Value, "Root Cage blocks moving physics body");
			float health2 = RootCage.Roots[1].Health;
			HitData val24 = new HitData();
			val24.m_damage.m_slash = RootCage.Health.Value + 1f;
			cageRoot.Damage(val24);
			Require(RootCage.Roots[1].Health == health2, "Root Cage roots have independent health");
			Require(!((Component)cageRoot).GetComponent<Collider>().enabled, "Root Cage destroyed segment immediately opens passage");
			probeBody.linearVelocity = ((Vector3)(ref towardsRoot)).normalized * 8f;
			yield return (object)new WaitForSeconds(0.4f);
			Require(Vector3.Dot(collisionProbe.transform.position - cageGround, ((Vector3)(ref towardsRoot)).normalized) > RootCage.Radius.Value + 0.3f, "Root Cage destroyed segment permits physical escape");
			Object.Destroy((Object)(object)collisionProbe);
			AccessTools.Field(typeof(RootCage), "expires").SetValue(null, Time.time - 1f);
			RootCage.Tick();
			Require(RootCage.Roots.Count == 0, "Root Cage duration cleanup removes all roots");
			plugin.InfoLog("BOSSMAGIC_CAGE_PASS: selection, cancellation, placement, costs, native visual isolation, collision, destruction, expiration.");
			yield return null;
			VineSwarm.Spread.Value = 0f;
			Require(VineSwarm.Give(player) != null, "Vine Swarm rune registered");
			Cursor.visible = false;
			Cursor.lockState = (CursorLockMode)1;
			Character vineEnemy = Target(((Component)player).transform.position + Vector3.forward * 7f, tamed: false);
			yield return (object)new WaitForSeconds(0.2f);
			MethodInfo controls = AccessTools.Method(typeof(Player), "SetControls", (Type[])null, (Type[])null);
			((Character)player).AddStamina(200f);
			VineSwarm.NextCast = 0f;
			object vineWeapon = AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player);
			Aim(player, vineEnemy.GetCenterPoint());
			Require(VineSwarm.TryCast(player) && VineSwarm.Active, "Vine Swarm begins channel");
			int startVines = VineSwarm.Shots;
			Vector3 startPosition = ((Component)player).transform.position;
			float beforeVineHealth = vineEnemy.GetHealth();
			controls.Invoke(player, new object[12]
			{
				Vector3.forward,
				false,
				false,
				false,
				false,
				false,
				false,
				true,
				true,
				true,
				true,
				true
			});
			val2 = (Vector3)AccessTools.Field(typeof(Character), "m_moveDir").GetValue(player);
			Require(((Vector3)(ref val2)).sqrMagnitude < 0.001f, "Vine Swarm suppresses movement controls");
			float vineStartTime = Time.time;
			while (Time.time - vineStartTime < VineSwarm.Duration.Value + 0.3f)
			{
				Aim(player, vineEnemy.GetCenterPoint());
				yield return (object)new WaitForSeconds(0.05f);
			}
			Require(!VineSwarm.Active && VineSwarm.Shots - startVines >= 5, "Vine Swarm emits repeated projectiles and ends naturally");
			Require(Vector3.Distance(((Component)player).transform.position, startPosition) < 0.3f, "Vine Swarm holds player position while channeling");
			Require(vineEnemy.GetHealth() < beforeVineHealth, "Vine Swarm projectiles damage hostile target");
			Require(AccessTools.Field(typeof(Humanoid), "m_rightItem").GetValue(player) == vineWeapon, "Vine Swarm preserves equipped weapon");
			controls.Invoke(player, new object[12]
			{
				Vector3.forward,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false
			});
			val2 = (Vector3)AccessTools.Field(typeof(Character), "m_moveDir").GetValue(player);
			Require(((Vector3)(ref val2)).sqrMagnitude > 0.1f, "Vine Swarm restores movement input after channel");
			controls.Invoke(player, new object[12]
			{
				Vector3.zero,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false
			});
			((Character)player).AddStamina(200f);
			VineSwarm.NextCast = 0f;
			Aim(player, vineEnemy.GetCenterPoint());
			Require(VineSwarm.TryCast(player), "Vine Swarm restarts for cancellation test");
			float stamina4 = player.GetStamina();
			int cancelShots = VineSwarm.Shots;
			Require(VineSwarm.TryCast(player) && !VineSwarm.Active && player.GetStamina() == stamina4, "Vine Swarm reuse cancels without extra cost");
			yield return (object)new WaitForSeconds(0.3f);
			Require(VineSwarm.Shots == cancelShots, "Vine Swarm cancellation stops further emission");
			((Character)player).AddStamina(200f);
			VineSwarm.NextCast = 0f;
			Require(VineSwarm.TryCast(player), "Vine Swarm restarts for block cancel");
			controls.Invoke(player, new object[12]
			{
				Vector3.zero,
				false,
				false,
				false,
				false,
				true,
				true,
				false,
				false,
				false,
				false,
				false
			});
			Require(!VineSwarm.Active, "Vine Swarm blocking cancels and frees player");
			controls.Invoke(player, new object[12]
			{
				Vector3.zero,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false,
				false
			});
			VineProjectile vineProbe = VineSwarm.Launch(player, ((Character)player).GetCenterPoint() + Vector3.up, Vector3.right);
			yield return (object)new WaitForSeconds(0.08f);
			((Component)Camera.main).transform.position = ((Character)player).GetCenterPoint() + Vector3.back * 5f + Vector3.up * 2f;
			((Component)Camera.main).transform.rotation = Quaternion.LookRotation(((Character)player).GetCenterPoint() + Vector3.right * 3f - ((Component)Camera.main).transform.position);
			RuneHotbarTest.Capture("vine-swarm.png");
			Require(Object.op_Implicit((Object)(object)vineProbe) && ((Component)vineProbe).GetComponentsInChildren<Projectile>().Length == 0 && ((Component)vineProbe).GetComponentsInChildren<ZNetView>().Length == 0, "Vine Swarm isolates native projectile visuals from gameplay scripts");
			Object.Destroy((Object)(object)((Component)vineProbe).gameObject);
			ZNetScene.instance.Destroy(((Component)vineEnemy).gameObject);
			plugin.InfoLog("BOSSMAGIC_VINES_PASS: channel, movement lock/restore, repeated projectiles, damage, equipment, reuse cancel, block cancel, native visuals.");
			IEnumerator hotbarTest = RuneHotbarTest.Run(player);
			while (hotbarTest.MoveNext())
			{
				yield return hotbarTest.Current;
			}
			GameObject val25 = Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("Greydwarf"), ((Component)player).transform.position + Vector3.right * 3f, Quaternion.identity);
			Character component = val25.GetComponent<Character>();
			Require(!TestArea.IsSubject(component), "ordinary creature is not a test subject");
			Require(TestArea.IsSubject(enemy) && TestArea.IsSubject(tame), "test subjects carry persistent identification");
			Require(TestArea.Reset(((Component)player).transform.position, 300f) >= 2 && Object.op_Implicit((Object)(object)component), "reset removes test enemies and allies while preserving ordinary creature");
			ZNetScene.instance.Destroy(val25);
			yield return null;
			Require(TestArea.Reset(((Component)player).transform.position, 300f) == 0, "reset is safe to repeat");
			plugin.InfoLog("BOSSMAGIC_AREA_PASS: marked targets, selective cleanup, repeated reset, automatic test cleanup.");
			player.SetGodMode(false);
			plugin.InfoLog("BOSSMAGIC_GAMEPLAY_PASS: hotbar, equipment, reuse, stamina, cooldown, projectile, electric damage, knockback, tame exclusion, wall occlusion.");
			RestoreTestConfig();
			Application.Quit(0);
		}
	}
	internal static class ImpactEffects
	{
		private static GameObject holder;

		private static GameObject stomp;

		private static GameObject sledge;

		internal static int Plays;

		internal static int SparkSystems;

		internal static int ThunderClips;

		internal static int SledgeSystems;

		internal static bool EffectsSafe;

		private static float nativeRadius = 5f;

		internal static void Prepare()
		{
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)holder))
			{
				return;
			}
			Humanoid component = PrefabManager.Instance.GetPrefab("Eikthyr").GetComponent<Humanoid>();
			GameObject prefab = (AccessTools.Field(typeof(Humanoid), "m_defaultItems").GetValue(component) as GameObject[]).First((GameObject w) => ((Object)w).name == "Eikthyr_stomp").GetComponent<ItemDrop>().m_itemData.m_shared.m_triggerEffect.m_effectPrefabs.First((EffectData e) => Object.op_Implicit((Object)(object)e.m_prefab) && ((Object)e.m_prefab).name == "fx_eikthyr_stomp").m_prefab;
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("SledgeIron").GetComponent<ItemDrop>().m_itemData.m_shared.m_triggerEffect.m_effectPrefabs.First((EffectData e) => Object.op_Implicit((Object)(object)e.m_prefab) && ((Object)e.m_prefab).name == "vfx_sledge_iron_hit").m_prefab;
			Plugin.instance.InfoLog("BOSSMAGIC_STOMP_COMPONENTS " + string.Join(",", (from c in prefab.GetComponentsInChildren<Component>(true)
				where Object.op_Implicit((Object)(object)c)
				select ((object)c).GetType().Name).Distinct()));
			ZSFX[] componentsInChildren = prefab.GetComponentsInChildren<ZSFX>(true);
			foreach (ZSFX val in componentsInChildren)
			{
				Plugin.instance.InfoLog("BOSSMAGIC_STOMP_AUDIO " + ((Object)val).name + " clips=" + string.Join(",", from c in val.m_audioClips
					where Object.op_Implicit((Object)(object)c)
					select ((Object)c).name));
			}
			Aoe componentInChildren = prefab.GetComponentInChildren<Aoe>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(Aoe), "m_radius");
				if (fieldInfo != null)
				{
					nativeRadius = Mathf.Max(1f, (float)fieldInfo.GetValue(componentInChildren));
				}
				DumpEffects("fx_eikthyr_stomp.aoe", componentInChildren);
			}
			holder = new GameObject("BossMagic_VisualTemplates");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			stomp = VisualOnly(prefab, "BossMagic_StompVisual");
			sledge = VisualOnly(prefab2, "BossMagic_SledgeVisual");
			SparkSystems = stomp.GetComponentsInChildren<ParticleSystem>(true).Length;
			ThunderClips = stomp.GetComponentsInChildren<ZSFX>(true).Sum((ZSFX s) => s.m_audioClips.Count((AudioClip c) => Object.op_Implicit((Object)(object)c)));
			SledgeSystems = sledge.GetComponentsInChildren<ParticleSystem>(true).Length;
			EffectsSafe = stomp.GetComponentsInChildren<Aoe>(true).Length == 0 && sledge.GetComponentsInChildren<Aoe>(true).Length == 0 && stomp.GetComponentsInChildren<Collider>(true).Length == 0 && sledge.GetComponentsInChildren<Collider>(true).Length == 0;
			Plugin.instance.InfoLog("BOSSMAGIC_IMPACT_ASSETS sparks=" + SparkSystems + " thunderClips=" + ThunderClips + " sledge=" + SledgeSystems + " visualOnly=" + EffectsSafe + " nativeRadius=" + nativeRadius);
		}

		private static GameObject VisualOnly(GameObject source, string name)
		{
			GameObject val = Object.Instantiate<GameObject>(source, holder.transform, false);
			((Object)val).name = name;
			MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if (!(val2 is ZSFX) && !(val2 is LightFlicker))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Rigidbody[] componentsInChildren3 = val.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			ZSFX[] componentsInChildren4 = val.GetComponentsInChildren<ZSFX>(true);
			foreach (ZSFX obj in componentsInChildren4)
			{
				obj.m_minVol *= 0.65f;
				obj.m_maxVol *= 0.65f;
				obj.m_useVibration = false;
			}
			val.SetActive(false);
			return val;
		}

		internal static void Play(Vector3 position, float radius)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Prepare();
			Spawn(stomp, position, Mathf.Clamp(radius / nativeRadius, 0.15f, 1f));
			Spawn(sledge, position, Mathf.Clamp(radius / 4f, 0.15f, 1.5f));
			Plays++;
		}

		private static void Spawn(GameObject template, Vector3 position, float scale)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			GameObject val = Object.Instantiate<GameObject>(template, position, Quaternion.identity);
			Transform transform = val.transform;
			transform.localScale *= scale;
			ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				MainModule main = componentsInChildren[i].main;
				((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
			}
			val.SetActive(true);
			Object.Destroy((Object)(object)val, 8f);
		}

		internal static void InspectAssets()
		{
			string[] array = new string[4] { "Eikthyr", "eikthyr_stomp", "SledgeIron", "SledgeStagbreaker" };
			foreach (string text in array)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				if (!Object.op_Implicit((Object)(object)prefab))
				{
					Plugin.instance.InfoLog("BOSSMAGIC_ASSET_MISSING " + text);
					continue;
				}
				ItemDrop component = prefab.GetComponent<ItemDrop>();
				if (Object.op_Implicit((Object)(object)component))
				{
					DumpEffects(text + ".shared", component.m_itemData.m_shared);
					DumpEffects(text + ".attack", component.m_itemData.m_shared.m_attack);
				}
				Humanoid component2 = prefab.GetComponent<Humanoid>();
				if (!Object.op_Implicit((Object)(object)component2) || !(AccessTools.Field(typeof(Humanoid), "m_defaultItems")?.GetValue(component2) is GameObject[] array2))
				{
					continue;
				}
				GameObject[] array3 = array2;
				foreach (GameObject val in array3)
				{
					Plugin.instance.InfoLog("BOSSMAGIC_BOSS_WEAPON " + ((Object)val).name);
					ItemDrop component3 = val.GetComponent<ItemDrop>();
					if (Object.op_Implicit((Object)(object)component3))
					{
						DumpEffects(((Object)val).name + ".shared", component3.m_itemData.m_shared);
						DumpEffects(((Object)val).name + ".attack", component3.m_itemData.m_shared.m_attack);
					}
				}
			}
			foreach (GameObject item in from o in Resources.FindObjectsOfTypeAll<GameObject>()
				where ((Object)o).name.StartsWith("sfx_eikthyr", StringComparison.OrdinalIgnoreCase) || ((Object)o).name.StartsWith("vfx_eikthyr", StringComparison.OrdinalIgnoreCase) || ((Object)o).name.StartsWith("vfx_sledge", StringComparison.OrdinalIgnoreCase)
				select o)
			{
				Plugin.instance.InfoLog("BOSSMAGIC_EFFECT_ASSET " + ((Object)item).name + " components=" + string.Join(",", (from c in item.GetComponentsInChildren<Component>(true)
					where Object.op_Implicit((Object)(object)c)
					select ((object)c).GetType().Name).Distinct()));
			}
		}

		private static void DumpEffects(string label, object data)
		{
			FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.FieldType != typeof(EffectList))
				{
					continue;
				}
				object? value = fieldInfo.GetValue(data);
				EffectList val = (EffectList)((value is EffectList) ? value : null);
				if (val?.m_effectPrefabs == null)
				{
					continue;
				}
				EffectData[] effectPrefabs = val.m_effectPrefabs;
				foreach (EffectData val2 in effectPrefabs)
				{
					if (Object.op_Implicit((Object)(object)val2.m_prefab))
					{
						Plugin.instance.InfoLog("BOSSMAGIC_EFFECT_REFERENCE " + label + "." + fieldInfo.Name + "=" + ((Object)val2.m_prefab).name);
					}
				}
			}
		}
	}
	internal static class LightningChain
	{
		private sealed class ChainCommand : ConsoleCommand
		{
			public override string Name => "bossmagic_chain";

			public override string Help => "Entrega a runa Lightning Chain experimental.";

			public override void Run(string[] args)
			{
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)ZNet.instance))
				{
					Give(Player.m_localPlayer);
				}
			}
		}

		internal const string RuneName = "BossMagic_LightningChainRune";

		internal static ConfigEntry<float> Cost;

		internal static ConfigEntry<float> Cooldown;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<float> Duration;

		internal static ConfigEntry<float> LeashLength;

		internal static ConfigEntry<float> PullSpeed;

		internal static bool Ready;

		internal static float NextCast;

		internal static Character Target;

		internal static Player caster;

		private static Player lastCaster;

		private static float expires;

		private static readonly Dictionary<Character, LineRenderer> links = new Dictionary<Character, LineRenderer>();

		internal static ConfigEntry<float> ChainRadius;

		internal static ConfigEntry<int> MaxTargets;

		private static Material material;

		private static readonly FieldInfo MoveDir = AccessTools.Field(typeof(Character), "m_moveDir");

		internal static Character[] LinkedTargets => links.Keys.Where((Character c) => Object.op_Implicit((Object)(object)c)).ToArray();

		internal static int TargetCount => links.Count;

		internal static bool IsLinked(Character target)
		{
			if (Object.op_Implicit((Object)(object)target))
			{
				return links.ContainsKey(target);
			}
			return false;
		}

		internal static void Initialize(Plugin host, Harmony harmony)
		{
			//IL_0122: 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_012f: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_01ec: Expected O, but got Unknown
			Cost = Bind(host, "ActivationStamina", 15f, 0f, 200f, "Custo inicial. Reativar para soltar nao custa estamina.");
			Cooldown = Bind(host, "Cooldown", 3f, 0f, 120f, "Recarga desde a ativacao.");
			Range = Bind(host, "Range", 20f, 3f, 60f, "Alcance da mira e distancia maxima antes de romper o vinculo.");
			Duration = Bind(host, "Duration", 10f, 1f, 120f, "Duracao maxima em segundos.");
			LeashLength = Bind(host, "LeashLength", 3f, 1f, 10f, "Comprimento livre da corrente antes de puxar.");
			PullSpeed = Bind(host, "PullSpeed", 6f, 1f, 20f, "Velocidade maxima de arrasto; valores provisorios.");
			ChainRadius = Bind(host, "ChainRadius", 6f, 1f, 20f, "Raio ao redor do PRIMEIRO alvo para capturar inimigos adicionais na ativacao.");
			MaxTargets = ((BaseUnityPlugin)host).Config.Bind<int>("LightningChain", "MaxTargets", 4, new ConfigDescription("Total maximo de criaturas, incluindo o primeiro alvo. 1 desativa a propagacao.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 12), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PrefabManager.OnVanillaPrefabsAvailable += Register;
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new ChainCommand());
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Humanoid), "UseItem", (Type[])null, (Type[])null), new HarmonyMethod(typeof(LightningChain), "Use", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Character), "UpdateMotion", (Type[])null, (Type[])null), new HarmonyMethod(typeof(LightningChain), "BeforeMotion", (Type[])null), new HarmonyMethod(typeof(LightningChain), "AfterMotion", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static ConfigEntry<float> Bind(Plugin host, string key, float value, float min, float max, string description)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			return ((BaseUnityPlugin)host).Config.Bind<float>("LightningChain", key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private static void Register()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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)
			CustomItem val = new CustomItem("BossMagic_LightningChainRune", "Stone", new ItemConfig
			{
				Name = "Runa de Lightning Chain",
				Description = "Prende o inimigo na mira e inimigos proximos com vinculos eletricos. Afaste-se para arrasta-lo; use novamente para soltar."
			});
			SharedData shared = val.ItemDrop.m_itemData.m_shared;
			shared.m_itemType = (ItemType)1;
			shared.m_maxStackSize = 1;
			shared.m_maxQuality = 1;
			shared.m_weight = 0.2f;
			Texture2D val2 = new Texture2D(64, 64, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					Vector2 val3 = new Vector2((float)(j - 32), (float)(i - 32));
					float magnitude = ((Vector2)(ref val3)).magnitude;
					bool flag = Mathf.Abs(Mathf.Pow(((float)j - 24f) / 10f, 2f) + Mathf.Pow(((float)i - 25f) / 15f, 2f) - 1f) < 0.3f;
					bool flag2 = Mathf.Abs(Mathf.Pow(((float)j - 40f) / 10f, 2f) + Mathf.Pow(((float)i - 39f) / 15f, 2f) - 1f) < 0.3f;
					array[i * 64 + j] = (Color)((magnitude > 29f) ? Color.clear : ((flag || flag2) ? new Color(0.9f, 1f, 1f) : new Color(0.12f, 0.17f, 0.32f)));
				}
			}
			val2.SetPixels(array);
			val2.Apply();
			shared.m_icons = (Sprite[])(object)new Sprite[1] { Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)) };
			if (!ItemManager.Instance.AddItem(val))
			{
				throw new InvalidOperationException("Lightning Chain registration failed");
			}
			Ready = true;
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			Plugin.instance.InfoLog("BOSSMAGIC_CHAIN_REGISTERED");
		}

		private static bool Use(Humanoid __instance, Inventory inventory, ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null || ((Object)item.m_dropPrefab).name != "BossMagic_LightningChainRune")
			{
				return true;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (Object.op_Implicit((Object)(object)val) && (Object)(object)val == (Object)(object)Player.m_localPlayer && (inventory == null || inventory == ((Humanoid)val).GetInventory()) && ((Humanoid)val).GetInventory().ContainsItem(item))
			{
				TryCast(val);
			}
			return false;
		}

		internal static bool ValidTarget(Character target, Player player)
		{
			if (MagicSystem.IsTarget(target, player) && !target.IsBoss() && Object.op_Implicit((Object)(object)((Component)target).GetComponent<Rigidbody>()))
			{
				return Object.op_Implicit((Object)(object)((Component)target).GetComponent<ZNetView>());
			}
			return false;
		}

		internal static Character FindTarget(Player player)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (m