Decompiled source of Leyline Guardian v1.0.0

plugins/LeylineGuardian/LeylineGuardian.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using Photon;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LeylineGuardian;

public sealed class BarrageData
{
	public sealed class Rock
	{
		public int Node;

		public int Ember;

		public float Fire;

		public float OutEnd;

		public float Recall;

		public float Arrival;

		public float Settle;

		public float Entry;

		public float Radius;

		public Vector3[] Path;
	}

	public Rock[] Rocks;

	public float[] Times;

	public Vector3[] Upper;

	public Vector3[] Hand;

	public float FirstFire = 100f;

	private static Vector3[] Vectors(BinaryReader r, int count)
	{
		//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)
		Vector3[] array = (Vector3[])(object)new Vector3[count];
		for (int i = 0; i < count; i++)
		{
			ref Vector3 reference = ref array[i];
			reference = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}
		return array;
	}

	public static BarrageData Load(string directory)
	{
		BarrageData barrageData = new BarrageData();
		using BinaryReader binaryReader = new BinaryReader(File.OpenRead(Path.Combine(directory, "barrage.bin")));
		if (new string(binaryReader.ReadChars(4)) != "LGBR" || binaryReader.ReadInt32() != 1 || binaryReader.ReadInt32() != 12)
		{
			throw new InvalidDataException("Unsupported barrage paths.");
		}
		barrageData.Rocks = new Rock[12];
		for (int i = 0; i < 12; i++)
		{
			Rock rock = new Rock();
			rock.Node = binaryReader.ReadInt32();
			rock.Ember = binaryReader.ReadInt32();
			rock.Fire = binaryReader.ReadSingle();
			rock.OutEnd = binaryReader.ReadSingle();
			rock.Recall = binaryReader.ReadSingle();
			rock.Arrival = binaryReader.ReadSingle();
			rock.Settle = binaryReader.ReadSingle();
			rock.Entry = binaryReader.ReadSingle();
			rock.Radius = binaryReader.ReadSingle();
			Rock rock2 = rock;
			if (!(rock2.Entry < rock2.Fire) || !(rock2.Fire < rock2.OutEnd) || !(rock2.OutEnd < rock2.Recall) || !(rock2.Recall < rock2.Arrival) || !(rock2.Arrival < rock2.Settle) || !(rock2.Radius > 0.1f) || !(rock2.Radius < 0.7f))
			{
				throw new InvalidDataException("Invalid barrage timing or radius.");
			}
			barrageData.Rocks[i] = rock2;
			barrageData.FirstFire = Mathf.Min(barrageData.FirstFire, rock2.Fire);
		}
		int num = binaryReader.ReadInt32();
		if (num < 2 || num > 10000)
		{
			throw new InvalidDataException("Invalid barrage sample count.");
		}
		barrageData.Times = new float[num];
		for (int j = 0; j < num; j++)
		{
			barrageData.Times[j] = binaryReader.ReadSingle();
		}
		for (int k = 1; k < num; k++)
		{
			if (barrageData.Times[k] <= barrageData.Times[k - 1])
			{
				throw new InvalidDataException("Unsorted barrage path.");
			}
		}
		barrageData.Upper = Vectors(binaryReader, num);
		barrageData.Hand = Vectors(binaryReader, num);
		Rock[] rocks = barrageData.Rocks;
		foreach (Rock rock3 in rocks)
		{
			rock3.Path = Vectors(binaryReader, num);
		}
		if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
		{
			throw new InvalidDataException("Unexpected barrage data.");
		}
		return barrageData;
	}

	public Vector3 Sample(Vector3[] path, float time)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		int num2 = Times.Length - 1;
		while (num + 1 < num2)
		{
			int num3 = (num + num2) / 2;
			if (Times[num3] <= time)
			{
				num = num3;
			}
			else
			{
				num2 = num3;
			}
		}
		return Vector3.Lerp(path[num], path[num2], Mathf.InverseLerp(Times[num], Times[num2], time));
	}
}
public static class BarrageRules
{
	public static float Smooth(float u)
	{
		u = Mathf.Clamp01(u);
		return u * u * (3f - 2f * u);
	}

	public static bool SegmentCapsule(Vector3 p, Vector3 q, Vector3 a, Vector3 b, float radius, out float fraction)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//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_0010: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_003b: 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_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = q - p;
		Vector3 val2 = b - a;
		Vector3 val3 = p - a;
		float num = Vector3.Dot(val, val);
		float num2 = Vector3.Dot(val2, val2);
		float num3 = Vector3.Dot(val, val2);
		float num4 = Vector3.Dot(val, val3);
		float num5 = Vector3.Dot(val2, val3);
		float num6;
		if (num < 1E-08f)
		{
			fraction = 0f;
			num6 = ((num2 < 1E-08f) ? 0f : Mathf.Clamp01(num5 / num2));
		}
		else if (num2 < 1E-08f)
		{
			num6 = 0f;
			fraction = Mathf.Clamp01((0f - num4) / num);
		}
		else
		{
			float num7 = num * num2 - num3 * num3;
			fraction = ((num7 > 1E-08f) ? Mathf.Clamp01((num3 * num5 - num4 * num2) / num7) : 0f);
			num6 = (num3 * fraction + num5) / num2;
			if (num6 < 0f)
			{
				num6 = 0f;
				fraction = Mathf.Clamp01((0f - num4) / num);
			}
			else if (num6 > 1f)
			{
				num6 = 1f;
				fraction = Mathf.Clamp01((num3 - num4) / num);
			}
		}
		Vector3 val4 = p + val * fraction - a - val2 * num6;
		return ((Vector3)(ref val4)).sqrMagnitude <= radius * radius;
	}
}
public sealed class BarrageDamageLedger
{
	private readonly Dictionary<int, uint> crossed = new Dictionary<int, uint>();

	private readonly Dictionary<int, float> nextHit = new Dictionary<int, float>();

	public void Clear()
	{
		crossed.Clear();
		nextHit.Clear();
	}

	public bool Cross(int player, int rock, bool returning, float time, bool eligible, float interval)
	{
		crossed.TryGetValue(player, out var value);
		uint num = (uint)(1 << rock + (returning ? 12 : 0));
		if ((value & num) != 0)
		{
			return false;
		}
		crossed[player] = value | num;
		int key = player * 2 + (returning ? 1 : 0);
		if (!eligible || (nextHit.TryGetValue(key, out var value2) && time < value2))
		{
			return false;
		}
		nextHit[key] = time + interval;
		return true;
	}
}
public sealed class BarrageAttack
{
	private sealed class State
	{
		public bool Launched;

		public bool OutBlocked;

		public bool ReturnBlocked;

		public float Fire;

		public float OutEnd;

		public float ReturnStopTime;

		public float Speed;

		public float Lead;

		public float Spread;

		public float Height;

		public float Bend;

		public float Arc;

		public float Kink;

		public Vector3 Launch;

		public Vector3 End;

		public Vector3 Side;

		public Vector3 OutStop;

		public Vector3 ReturnStop;
	}

	private struct Flight
	{
		public Vector3 Launch;

		public Vector3 End;

		public Vector3 Side;

		public float OutEnd;
	}

	private readonly GuardianModel model;

	private readonly BarrageData data;

	private readonly Transform upper;

	private readonly Transform owner;

	private readonly int environmentMask;

	private readonly State[] states = new State[12];

	private Vector3 target;

	private Vector3 previousTarget;

	private Vector3 targetVelocity;

	private Vector3 previousVelocity;

	private float targetTime;

	private float previousTargetTime;

	internal Action<Vector3> LaunchedSound;

	internal Action<Vector3> BlockedSound;

	public bool Active { get; private set; }

	public Vector3 Target => target;

	public int WallStops { get; private set; }

	public float FirstFire { get; private set; }

	public float FiringUntil
	{
		get
		{
			float num = 0f;
			for (int i = 0; i < 12; i++)
			{
				num = Mathf.Max(num, OutEndTime(i));
			}
			return num;
		}
	}

	public BarrageAttack(GuardianModel m, BarrageData paths, int mask)
	{
		model = m;
		data = paths;
		environmentMask = mask;
		upper = m.Find("UpperArm.R");
		owner = (Object.op_Implicit((Object)(object)((Component)m).transform.parent) ? ((Component)m).transform.parent : ((Component)m).transform);
		if (!Object.op_Implicit((Object)(object)upper))
		{
			throw new InvalidDataException("Missing barrage arm.");
		}
		BarrageData.Rock[] rocks = paths.Rocks;
		foreach (BarrageData.Rock rock in rocks)
		{
			if (rock.Node < 0 || rock.Node >= m.Nodes.Length || rock.Ember < 0 || rock.Ember >= m.Nodes.Length)
			{
				throw new InvalidDataException("Barrage node unavailable.");
			}
		}
	}

	private static float Range(Random random, float min, float max)
	{
		return Mathf.Lerp(min, max, (float)random.NextDouble());
	}

	public void Begin(Vector3 worldTarget)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		Begin(worldTarget, Random.Range(1, int.MaxValue));
	}

	public void Begin(Vector3 worldTarget, int seed)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: 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_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		target = (previousTarget = worldTarget);
		targetVelocity = (previousVelocity = Vector3.zero);
		targetTime = (previousTargetTime = 0f);
		Active = true;
		WallStops = 0;
		FirstFire = 100f;
		Random random = new Random(seed);
		int[] array = new int[12];
		for (int i = 0; i < 12; i++)
		{
			array[i] = i;
		}
		Array.Sort(array, (int a, int b) => data.Rocks[a].Fire.CompareTo(data.Rocks[b].Fire));
		float num = 0f;
		int[] array2 = array;
		foreach (int num3 in array2)
		{
			State state = new State();
			states[num3] = state;
			state.Fire = Mathf.Max(num + 0.026f, data.Rocks[num3].Fire + Range(random, -0.032f, 0.032f));
			num = state.Fire;
			FirstFire = Mathf.Min(FirstFire, state.Fire);
			state.Speed = Range(random, 23f, 35f);
			state.Lead = Range(random, 0.88f, 1.12f);
			state.Spread = Range(random, -0.34f, 0.34f);
			state.Height = Range(random, -0.12f, 0.12f);
			state.Bend = Range(random, -0.55f, 0.55f);
			state.Arc = Range(random, -0.1f, 0.28f);
			state.Kink = Range(random, -0.18f, 0.18f);
		}
	}

	public void Cancel()
	{
		Active = false;
	}

	public Vector3 PredictedLaunch(int i)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return FlightFor(i).Launch;
	}

	public bool CanFireAt(Vector3 aimTarget, Vector3 velocity, int seed, int requiredClearShots = 4)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		Begin(aimTarget, seed);
		targetVelocity = (previousVelocity = Vector3.ClampMagnitude(velocity, 10f));
		int num = 0;
		for (int i = 0; i < 12; i++)
		{
			Flight flight = FlightFor(i);
			float num2 = Vector3.Distance(flight.Launch, flight.End);
			float num3 = Mathf.Clamp01((num2 - 3.2f - 0.35f) / Mathf.Max(0.01f, num2));
			int num4 = Mathf.Clamp(Mathf.CeilToInt(num2 / 1.5f), 16, 48);
			Vector3 val = flight.Launch;
			bool flag = false;
			for (int j = 1; j <= num4; j++)
			{
				float time = Mathf.Lerp(states[i].Fire, flight.OutEnd, num3 * (float)j / (float)num4);
				Vector3 val2 = UnblockedWorldPosition(i, time);
				if (SweepWall(val, val2, data.Rocks[i].Radius, out var _))
				{
					flag = true;
					break;
				}
				val = val2;
			}
			if (!flag && ++num >= requiredClearShots)
			{
				return true;
			}
			if (num + 11 - i < requiredClearShots)
			{
				return false;
			}
		}
		return false;
	}

	public float FireTime(int i)
	{
		return states[i].Fire;
	}

	public float OutEndTime(int i)
	{
		return FlightFor(i).OutEnd;
	}

	public void UpdateAim(Vector3 worldTarget, float time)
	{
		//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)
		UpdateAim(worldTarget, Vector3.zero, time);
	}

	public void UpdateAim(Vector3 worldTarget, Vector3 velocity, float time)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		if (Active && !(previousTargetTime > FiringUntil))
		{
			previousTarget = target;
			previousVelocity = targetVelocity;
			previousTargetTime = targetTime;
			target = worldTarget;
			targetVelocity = Vector3.ClampMagnitude(velocity, 10f);
			targetTime = time;
		}
	}

	private Vector3 TargetAt(float time)
	{
		//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Lerp(previousTarget, target, Mathf.InverseLerp(previousTargetTime, targetTime, time));
	}

	private Vector3 VelocityAt(float time)
	{
		//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Lerp(previousVelocity, targetVelocity, Mathf.InverseLerp(previousTargetTime, targetTime, time));
	}

	private Quaternion Aim(float time, Vector3 aimTarget)
	{
		//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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//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_008e: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = data.Sample(data.Upper, time);
		Vector3 val2 = data.Sample(data.Hand, time);
		Vector3 val3 = ((Component)model).transform.InverseTransformPoint(aimTarget) - val;
		if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
		{
			return Quaternion.identity;
		}
		float num = BarrageRules.Smooth((time - 0.4f) / 0.65f) * (1f - BarrageRules.Smooth((time - 4.55f) / 0.95f));
		return Quaternion.Slerp(Quaternion.identity, Quaternion.FromToRotation(val2 - val, val3), num);
	}

	private Vector3 GatherWorld(int i, float time, Vector3 aimTarget)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		BarrageData.Rock rock = data.Rocks[i];
		float time2 = ((time <= rock.Entry) ? time : Mathf.Lerp(rock.Entry, rock.Fire, Mathf.InverseLerp(rock.Entry, states[i].Fire, time)));
		Vector3 val = data.Sample(rock.Path, time2);
		Vector3 val2 = data.Sample(data.Upper, time2);
		Vector3 val3 = data.Sample(data.Upper, time);
		float num = BarrageRules.Smooth((time - rock.Entry + 0.32f) / 0.32f);
		Vector3 val4 = val3 + Quaternion.Slerp(Quaternion.identity, Aim(time, aimTarget), num) * (val - val2);
		return ((Component)model).transform.TransformPoint(val4);
	}

	private static float InterceptTime(Vector3 offset, Vector3 velocity, float speed)
	{
		//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)
		float num = ((Vector3)(ref velocity)).sqrMagnitude - speed * speed;
		float num2 = 2f * Vector3.Dot(offset, velocity);
		float sqrMagnitude = ((Vector3)(ref offset)).sqrMagnitude;
		float num3 = ((Vector3)(ref offset)).magnitude / speed;
		float num4 = num2 * num2 - 4f * num * sqrMagnitude;
		if (Mathf.Abs(num) > 0.0001f && num4 >= 0f)
		{
			float num5 = Mathf.Sqrt(num4);
			float num6 = (0f - num2 - num5) / (2f * num);
			float num7 = (0f - num2 + num5) / (2f * num);
			if (num6 > 0f && num7 > 0f)
			{
				num3 = Mathf.Min(num6, num7);
			}
			else if (num6 > 0f)
			{
				num3 = num6;
			}
			else if (num7 > 0f)
			{
				num3 = num7;
			}
		}
		else if (Mathf.Abs(num2) > 0.0001f && (0f - sqrMagnitude) / num2 > 0f)
		{
			num3 = (0f - sqrMagnitude) / num2;
		}
		return Mathf.Clamp(num3, 0f, 1.05f);
	}

	private Flight FlightFor(int i)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		State state = states[i];
		if (state.Launched)
		{
			return new Flight
			{
				Launch = state.Launch,
				End = state.End,
				Side = state.Side,
				OutEnd = state.OutEnd
			};
		}
		Vector3 val = TargetAt(state.Fire);
		Vector3 val2 = VelocityAt(state.Fire);
		Vector3 val3 = GatherWorld(i, state.Fire, val);
		float num = Mathf.Min(1.05f, data.Rocks[i].Recall - 0.12f - state.Fire);
		float num2 = Vector3.Distance(val3, val);
		float speed = Mathf.Max(state.Speed, (num2 + 3.2f) / Mathf.Max(0.1f, num));
		Vector3 val4 = val + val2 * (InterceptTime(val - val3, val2, speed) * state.Lead);
		Vector3 val5 = val4 - val3;
		Vector3 normalized = ((Vector3)(ref val5)).normalized;
		Vector3 val6 = Vector3.Cross(Vector3.up, normalized);
		Vector3 val7 = ((Vector3)(ref val6)).normalized;
		if (((Vector3)(ref val7)).sqrMagnitude < 0.01f)
		{
			val7 = ((Component)model).transform.right;
		}
		Vector3 val8 = val4 + val7 * state.Spread + Vector3.up * state.Height + normalized * 3.2f;
		float num3 = Mathf.Clamp(Vector3.Distance(val3, val8) / state.Speed, 0.22f, 1.05f);
		float outEnd = Mathf.Min(state.Fire + num3, data.Rocks[i].Recall - 0.12f);
		return new Flight
		{
			Launch = val3,
			End = val8,
			Side = val7,
			OutEnd = outEnd
		};
	}

	private void Launch(int i)
	{
		//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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		State state = states[i];
		if (!state.Launched)
		{
			Flight flight = FlightFor(i);
			state.Launch = flight.Launch;
			state.End = flight.End;
			state.Side = flight.Side;
			state.OutEnd = flight.OutEnd;
			state.Launched = true;
			if (LaunchedSound != null)
			{
				LaunchedSound(state.Launch);
			}
		}
	}

	public Vector3 UnblockedWorldPosition(int i, float time)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		State state = states[i];
		BarrageData.Rock rock = data.Rocks[i];
		if (time < state.Fire || (time == state.Fire && !state.Launched))
		{
			return GatherWorld(i, time, TargetAt(time));
		}
		Flight flight = FlightFor(i);
		if (time < flight.OutEnd)
		{
			float num = Mathf.InverseLerp(state.Fire, flight.OutEnd, time);
			float num2 = Mathf.Sin(num * (float)Math.PI);
			Vector3 val = flight.Side * (state.Bend * num2 + state.Kink * Mathf.Sin(num * (float)Math.PI * 2f) * num2) + Vector3.up * (state.Arc * num2);
			return Vector3.Lerp(flight.Launch, flight.End, num) + val;
		}
		float time2 = ((time < rock.Recall) ? Mathf.Lerp(rock.OutEnd, rock.Recall, Mathf.InverseLerp(flight.OutEnd, rock.Recall, time)) : time);
		Vector3 val2 = ((Component)model).transform.TransformPoint(data.Sample(rock.Path, time2));
		Vector3 val3 = ((Component)model).transform.TransformPoint(data.Sample(rock.Path, rock.OutEnd));
		float num3 = 1f - BarrageRules.Smooth(Mathf.InverseLerp(rock.Recall, rock.Arrival, time));
		return val2 + (flight.End - val3) * num3;
	}

	public Vector3 UnblockedLocalPosition(int i, float time)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		return ((Component)model).transform.InverseTransformPoint(UnblockedWorldPosition(i, time));
	}

	public Vector3 WorldPosition(int i, float time)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		BarrageData.Rock rock = data.Rocks[i];
		State state = states[i];
		if (state.ReturnBlocked && time < rock.Arrival)
		{
			return state.ReturnStop;
		}
		if (state.OutBlocked && time < rock.Recall)
		{
			return state.OutStop;
		}
		Vector3 val = UnblockedWorldPosition(i, time);
		if (state.OutBlocked && time < rock.Arrival)
		{
			val += (state.OutStop - UnblockedWorldPosition(i, rock.Recall)) * (1f - BarrageRules.Smooth(Mathf.InverseLerp(rock.Recall, rock.Arrival, time)));
		}
		return val;
	}

	public Vector3 LocalPosition(int i, float time)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		return ((Component)model).transform.InverseTransformPoint(WorldPosition(i, time));
	}

	private bool SweepWall(Vector3 from, Vector3 to, float radius, out Vector3 stop)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: 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_0019: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		stop = to;
		if (environmentMask == 0)
		{
			return false;
		}
		Vector3 val = to - from;
		float magnitude = ((Vector3)(ref val)).magnitude;
		float num = magnitude + 1f;
		Collider[] array = Physics.OverlapSphere(from, radius, environmentMask, (QueryTriggerInteraction)1);
		foreach (Collider val2 in array)
		{
			if (Object.op_Implicit((Object)(object)val2) && !((Component)val2).transform.IsChildOf(owner) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<Character>()))
			{
				stop = from;
				return true;
			}
		}
		if (magnitude < 1E-06f)
		{
			return false;
		}
		RaycastHit[] array2 = Physics.SphereCastAll(from, radius, val / magnitude, magnitude, environmentMask, (QueryTriggerInteraction)1);
		for (int j = 0; j < array2.Length; j++)
		{
			RaycastHit val3 = array2[j];
			if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val3)).collider) && !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(owner) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<Character>()) && ((RaycastHit)(ref val3)).distance < num)
			{
				num = ((RaycastHit)(ref val3)).distance;
			}
		}
		if (num > magnitude)
		{
			return false;
		}
		stop = from + val / magnitude * Mathf.Max(0f, num - 0.015f);
		return true;
	}

	public void Advance(float before, float now, Action<int, bool, Vector3, Vector3, float> segment)
	{
		if (!Active)
		{
			return;
		}
		float num = before;
		while (num < now - 1E-06f)
		{
			float num2 = Mathf.Min(now, (Mathf.Floor(num * 120f + 0.0001f) + 1f) / 120f);
			if (num2 <= num)
			{
				num2 = Mathf.Min(now, num + 1f / 120f);
			}
			for (int i = 0; i < 12; i++)
			{
				State state = states[i];
				BarrageData.Rock rock = data.Rocks[i];
				if (num2 >= state.Fire)
				{
					Launch(i);
				}
				SweepPhase(i, returning: false, Mathf.Max(num, state.Fire), Mathf.Min(num2, OutEndTime(i)), segment);
				SweepPhase(i, returning: true, Mathf.Max(num, rock.Recall), Mathf.Min(num2, rock.Arrival), segment);
			}
			num = num2;
		}
		Apply(now);
	}

	private void SweepPhase(int i, bool returning, float start, float end, Action<int, bool, Vector3, Vector3, float> segment)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		State state = states[i];
		if (end <= start || (returning ? state.ReturnBlocked : state.OutBlocked))
		{
			return;
		}
		int num = Mathf.Max(1, Mathf.CeilToInt((end - start) * 120f));
		Vector3 val = WorldPosition(i, start);
		for (int j = 1; j <= num; j++)
		{
			float num2 = Mathf.Lerp(start, end, (float)j / (float)num);
			Vector3 val2 = WorldPosition(i, num2);
			Vector3 stop;
			bool flag = SweepWall(val, val2, data.Rocks[i].Radius, out stop);
			segment?.Invoke(i, returning, val, flag ? stop : val2, num2);
			if (flag)
			{
				WallStops++;
				if (BlockedSound != null)
				{
					BlockedSound(stop);
				}
				if (returning)
				{
					state.ReturnBlocked = true;
					state.ReturnStop = stop;
					state.ReturnStopTime = num2;
				}
				else
				{
					state.OutBlocked = true;
					state.OutStop = stop;
				}
				break;
			}
			val = val2;
		}
	}

	public void Apply(float time)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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_0170: 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_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			return;
		}
		Quaternion val = ((Component)model).transform.rotation * Aim(time, target) * Quaternion.Inverse(((Component)model).transform.rotation);
		upper.rotation = val * upper.rotation;
		for (int i = 0; i < 12; i++)
		{
			BarrageData.Rock rock = data.Rocks[i];
			State state = states[i];
			Transform val2 = model.Nodes[rock.Node];
			Transform val3 = model.Nodes[rock.Ember];
			Vector3 val4 = (val3.position = (val2.position = WorldPosition(i, time)));
			if (state.ReturnBlocked)
			{
				float num = ((time < rock.Arrival) ? (1f - BarrageRules.Smooth((time - state.ReturnStopTime) / 0.14f)) : BarrageRules.Smooth((time - rock.Arrival) / 0.18f));
				val2.localScale *= num;
				val3.localScale *= num;
			}
			else if (state.OutBlocked && time < rock.Recall)
			{
				val3.localScale *= 0.35f;
			}
			Vector3 val7 = WorldPosition(i, Mathf.Min(time + 0.008f, rock.Settle)) - val4;
			if (((Vector3)(ref val7)).sqrMagnitude > 1E-06f)
			{
				val3.rotation = Quaternion.LookRotation(((Vector3)(ref val7)).normalized);
			}
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("local.val.leylineguardian", "Leyline Guardian", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
	internal ConfigEntry<float> BarragePhysical;

	internal ConfigEntry<float> BarrageEthereal;

	internal ConfigEntry<float> BarrageImpact;

	internal ConfigEntry<float> BarrageHitInterval;

	internal ConfigEntry<float> ChargePhysical;

	internal ConfigEntry<float> ChargeEthereal;

	internal ConfigEntry<float> ChargeImpact;

	internal ConfigEntry<float> ChargeCooldown;

	internal ConfigEntry<float> BeamEthereal;

	internal ConfigEntry<float> BeamImpact;

	internal ConfigEntry<float> BeamCooldown;

	internal ConfigEntry<float> WalkSpeed;

	internal ConfigEntry<bool> SoundEnabled;

	internal ConfigEntry<float> SoundVolume;

	internal ConfigEntry<float> GuardianVolume;

	internal ConfigEntry<float> StepVolume;

	internal ConfigEntry<float> HumVolume;

	internal GuardianAudioBus AudioBus;

	private GuardianSoundBank soundBank;

	private bool soundFailed;

	internal ConfigEntry<float> PhysicalResistance;

	internal ConfigEntry<float> MagicResistance;

	internal ConfigEntry<float> FireResistance;

	internal ConfigEntry<float> Barrier;

	private GuardianEncounterState pendingEncounter;

	private SL_Item coreTemplate;

	private Sprite coreIcon;

	private Texture2D coreTexture;

	private ConfigEntry<bool> worldSpawnEnabled;

	private bool worldSuppressed;

	private bool corpseSuppressed;

	private bool pendingCorpse;

	private float nextWorldCheck;

	private string pendingWorldUID;

	private string activeWorldUID;

	private SL_Weapon leylineMace;

	private SL_Weapon leylineHammer;

	internal static Plugin Instance;

	internal GuardianAsset Asset;

	private SL_Character template;

	internal GuardianBoss Boss;

	private Character spawning;

	private bool busy;

	private bool loading;

	private GuardianNetwork network;

	private int generation;

	private string pendingUID;

	private float spawnDeadline;

	internal ConfigEntry<float> Health;

	internal ConfigEntry<float> Protection;

	internal ConfigEntry<float> PhysicalDamage;

	internal ConfigEntry<float> EtherealDamage;

	internal ConfigEntry<float> Impact;

	internal ConfigEntry<float> RupturePhysical;

	internal ConfigEntry<float> RuptureEthereal;

	internal ConfigEntry<float> RuptureImpact;

	internal ConfigEntry<float> RuptureCooldown;

	internal ConfigEntry<float> UltimateEthereal;

	internal ConfigEntry<float> UltimateLightning;

	internal ConfigEntry<float> UltimateImpact;

	internal ConfigEntry<float> UltimateCooldown;

	internal ConfigEntry<float> FinaleEthereal;

	internal ConfigEntry<float> FinaleLightning;

	internal ConfigEntry<float> FinaleImpact;

	internal bool CoreReady
	{
		get
		{
			if (coreTemplate != null && Object.op_Implicit((Object)(object)coreTemplate.CurrentPrefab) && (Object)(object)coreTemplate.CurrentPrefab.ItemIcon == (Object)(object)coreIcon && coreTemplate.CurrentPrefab.RawWeight == 0.5f)
			{
				return coreTemplate.CurrentPrefab.RawBaseValue == 250;
			}
			return false;
		}
	}

	private bool InGuardianArea
	{
		get
		{
			//IL_000d: 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)
			if (worldSpawnEnabled.Value)
			{
				Scene activeScene = SceneManager.GetActiveScene();
				return ((Scene)(ref activeScene)).name == "ChersoneseNewTerrain";
			}
			return false;
		}
	}

	private void BindBarrage()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		BarragePhysical = ((BaseUnityPlugin)this).Config.Bind<float>("Barrage", "PhysicalDamage", 6f, new ConfigDescription("Physical damage per accepted rock hit, outbound and return.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		BarrageEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("Barrage", "EtherealDamage", 8f, new ConfigDescription("Ethereal damage per accepted rock hit, outbound and return.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		BarrageImpact = ((BaseUnityPlugin)this).Config.Bind<float>("Barrage", "Impact", 12f, new ConfigDescription("Native stability impact per accepted rock hit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		BarrageHitInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Barrage", "HitInterval", 0.18f, new ConfigDescription("Minimum seconds between damaging rocks in each pass; prevents simultaneous recall hits stacking unfairly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), new object[0]));
	}

	private void BindCharge()
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		ChargePhysical = ((BaseUnityPlugin)this).Config.Bind<float>("Charge", "PhysicalDamage", 20f, (ConfigDescription)null);
		ChargeEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("Charge", "EtherealDamage", 12f, (ConfigDescription)null);
		ChargeImpact = ((BaseUnityPlugin)this).Config.Bind<float>("Charge", "Impact", 55f, (ConfigDescription)null);
		ChargeCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Charge", "Cooldown", 20f, new ConfigDescription("Seconds between autonomous charges.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 60f), new object[0]));
	}

	private void BindBeam()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		BeamEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("CoreBeam", "EtherealDamage", 18f, new ConfigDescription("Ethereal damage per pulse; four pulses, 72 total before defenses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		BeamImpact = ((BaseUnityPlugin)this).Config.Bind<float>("CoreBeam", "Impact", 18f, new ConfigDescription("Native stability impact per beam pulse.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		BeamCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("CoreBeam", "Cooldown", 26f, new ConfigDescription("Seconds between autonomous chest beams.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(12f, 90f), new object[0]));
	}

	private void BindAI()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		WalkSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("AI", "WalkSpeed", 1.65f, new ConfigDescription("Ground movement speed in metres per second; gait follows actual movement.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 3f), new object[0]));
	}

	private void BindAudio()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		SoundEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "Enabled", true, "Enable Guardian and Leyline weapon sounds.");
		GuardianVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "GuardianVolume", 0.7f, new ConfigDescription("Relative Guardian loudness; Leyline weapon abilities keep their own level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 0.85f, new ConfigDescription("Guardian audio level; also follows the game's master and SFX volumes.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		StepVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "FootstepsVolume", 0.6f, new ConfigDescription("Relative footstep level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		HumVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "CoreHumVolume", 0.18f, new ConfigDescription("Relative quiet core ambience level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("Audio", "MixRevision", 0, "Tracks the quieter audio mix migration.");
		if (val.Value < 1)
		{
			StepVolume.Value = Mathf.Min(StepVolume.Value, 0.6f);
			HumVolume.Value = Mathf.Min(HumVolume.Value, 0.18f);
			val.Value = 1;
		}
	}

	internal GuardianAudioBus EnsureAudio()
	{
		if (Object.op_Implicit((Object)(object)AudioBus) || soundFailed)
		{
			return AudioBus;
		}
		try
		{
			soundBank = GuardianSoundBank.Load(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Audio"));
			soundBank.UseNativeFootsteps();
			AudioBus = ((Component)this).gameObject.AddComponent<GuardianAudioBus>();
			AudioBus.Initialize(this, soundBank);
		}
		catch (Exception ex)
		{
			soundFailed = true;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Guardian audio unavailable; combat remains active: " + ex.Message));
		}
		return AudioBus;
	}

	internal static void WeaponSound(string name, Vector3 at, float gain = 1f)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)Instance))
		{
			GuardianAudioBus guardianAudioBus = Instance.EnsureAudio();
			if (Object.op_Implicit((Object)(object)guardianAudioBus))
			{
				guardianAudioBus.Play(name, at, gain, 1.5f, 3);
			}
		}
	}

	private void DisposeAudio()
	{
		if (Object.op_Implicit((Object)(object)AudioBus))
		{
			AudioBus.Silence();
			Object.Destroy((Object)(object)AudioBus);
			AudioBus = null;
		}
		if (soundBank != null)
		{
			soundBank.Dispose();
			soundBank = null;
		}
	}

	private void BindDefenses()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		PhysicalResistance = ((BaseUnityPlugin)this).Config.Bind<float>("Defenses", "PhysicalResistance", 40f, new ConfigDescription("Physical damage resistance percentage for newly spawned Guardians.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		MagicResistance = ((BaseUnityPlugin)this).Config.Bind<float>("Defenses", "MagicResistance", 80f, new ConfigDescription("Ethereal, decay, lightning and frost resistance percentage for newly spawned Guardians.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		FireResistance = ((BaseUnityPlugin)this).Config.Bind<float>("Defenses", "FireResistance", 95f, new ConfigDescription("Fire damage resistance percentage for newly spawned Guardians.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		Barrier = ((BaseUnityPlugin)this).Config.Bind<float>("Defenses", "Barrier", 8f, new ConfigDescription("Flat magical barrier for newly spawned Guardians, before native resistance calculations.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[0]));
	}

	internal static float[] ResistanceValues(float physical, float magic, float fire)
	{
		//IL_002d: 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)
		float[] array = new float[6] { physical, 0f, 0f, 0f, 0f, 0f };
		Types[] array2 = (Types[])(object)new Types[4]
		{
			(Types)1,
			(Types)2,
			(Types)3,
			(Types)4
		};
		foreach (Types val in array2)
		{
			array[val] = magic;
		}
		array[5] = fire;
		return array;
	}

	private float[] ResistanceValues()
	{
		return ResistanceValues(PhysicalResistance.Value, MagicResistance.Value, FireResistance.Value);
	}

	internal void CacheEncounter()
	{
		if (!GuardianNetwork.Authority || !Object.op_Implicit((Object)(object)Boss) || Boss.Replica || string.IsNullOrEmpty(Boss.PersistentWorldUID))
		{
			return;
		}
		GuardianEncounterState current = GuardianEncounterStore.Current;
		if (current == null || !(current.WorldUID != Boss.PersistentWorldUID) || !(WorldUID() != Boss.PersistentWorldUID))
		{
			GuardianEncounterState guardianEncounterState = Boss.CaptureEncounter();
			if (guardianEncounterState != null)
			{
				GuardianEncounterStore.Current = guardianEncounterState;
				GuardianEncounterStore.InvalidPayload = null;
			}
		}
	}

	private void RegisterLeylineCore()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Expected O, but got Unknown
		coreTexture = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(coreTexture, File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "leyline-core-icon.png"))))
		{
			throw new InvalidDataException("Leyline Core icon could not load");
		}
		((Object)coreTexture).name = "Leyline Core approved icon";
		coreIcon = Sprite.Create(coreTexture, new Rect(0f, 0f, (float)((Texture)coreTexture).width, (float)((Texture)coreTexture).height), new Vector2(0.5f, 0.5f), 100f);
		((Object)coreIcon).name = "Leyline Core";
		SL_Item val = new SL_Item();
		val.Target_ItemID = 6200130;
		val.New_ItemID = 9024780;
		val.Name = "Leyline Core Shard";
		val.Description = "A fractured heart of crystallized mana, torn from the Leyline Guardian's chest. Violet energy still courses through its weathered stone shell, stirring runes that should have fallen silent.";
		val.IsUsable = false;
		val.IsPickable = true;
		val.OverrideSellModifier = 1f;
		SL_ItemStats val2 = new SL_ItemStats();
		val2.RawWeight = 0.5f;
		val2.BaseValue = 250;
		val.StatsHolder = val2;
		coreTemplate = val;
		coreTemplate.OnTemplateApplied += CoreApplied;
		coreTemplate.AddOnInstanceStartListener((Action<Item>)ApplyCoreIcon);
		SL.OnPacksLoaded += ApplyLeylineCore;
		if (SL.PacksLoaded)
		{
			ApplyLeylineCore();
		}
	}

	private void ApplyLeylineCore()
	{
		try
		{
			ValidateCoreID(coreTemplate);
			if (GuardianLootRules.Prefabs.TryGetValue(9024780.ToString(), out var value) && (Object)(object)value == (Object)(object)coreTemplate.CurrentPrefab)
			{
				ApplyLeylineWeapons();
				return;
			}
			((ContentTemplate)coreTemplate).ApplyTemplate();
			ApplyLeylineWeapons();
		}
		catch (Exception e)
		{
			Failure(e);
		}
	}

	private static void ValidateCoreID(SL_Item template)
	{
		if (GuardianLootRules.Prefabs.TryGetValue(9024780.ToString(), out var value) && Object.op_Implicit((Object)(object)value) && (Object)(object)value != (Object)(object)template.CurrentPrefab)
		{
			throw new InvalidOperationException("Leyline Core item ID is already registered; refusing to replace another mod's item");
		}
	}

	private void ApplyCoreIcon(Item item)
	{
		CustomItemVisuals.SetSpriteLink(item, coreIcon, false);
		AccessTools.Field(typeof(Item), "m_itemIcon").SetValue(item, coreIcon);
	}

	private void CoreApplied(Item item)
	{
		ApplyCoreIcon(item);
		item.ForceNonSavable = false;
	}

	private IEnumerator FinishReplica(Character character)
	{
		yield return (object)new WaitForSeconds(1f);
		while (Object.op_Implicit((Object)(object)character) && (!character.IsStartInitDone || !character.IsLateInitDone))
		{
			yield return null;
		}
		if (!Object.op_Implicit((Object)(object)character) || Authority())
		{
			yield break;
		}
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name != "ChersoneseNewTerrain")
		{
			yield break;
		}
		if (Object.op_Implicit((Object)(object)Boss))
		{
			if (!((Object)(object)Boss.Character == (Object)(object)character))
			{
				GuardianNetwork.DestroyLocal(character);
			}
			yield break;
		}
		if (Asset == null)
		{
			while (loading)
			{
				yield return null;
			}
			if (Asset == null)
			{
				loading = true;
				IEnumerator load = GuardianAsset.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), delegate(GuardianAsset a)
				{
					Asset = a;
				});
				try
				{
					while (load.MoveNext())
					{
						yield return load.Current;
					}
				}
				finally
				{
					loading = false;
					((IDisposable)load).Dispose();
				}
			}
		}
		if (!Object.op_Implicit((Object)(object)character) || Authority())
		{
			yield break;
		}
		Scene activeScene2 = SceneManager.GetActiveScene();
		if (!(((Scene)(ref activeScene2)).name != "ChersoneseNewTerrain") && !Object.op_Implicit((Object)(object)Boss))
		{
			Boss = ((Component)character).gameObject.AddComponent<GuardianBoss>();
			Boss.Replica = true;
			Boss.PersistentWorldUID = WorldUID();
			Boss.Initialize(character, Asset);
			Boss.Autonomous = false;
			if (Object.op_Implicit((Object)(object)((MonoBehaviour)character).photonView))
			{
				((MonoBehaviour)character).photonView.RPC("RequestSyncInfo", (PhotonTargets)2, new object[0]);
			}
			if (network.Latest != null && network.Latest.Actor == UID.op_Implicit(character.UID))
			{
				Boss.AcceptNetwork(network.Latest);
			}
		}
	}

	private void TickStoredEncounterRecovery()
	{
		//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)
		if (Object.op_Implicit((Object)(object)Boss) || busy || loading || PhotonNetwork.isNonMasterClientInRoom)
		{
			return;
		}
		Scene activeScene = SceneManager.GetActiveScene();
		if (!(((Scene)(ref activeScene)).name == "ChersoneseNewTerrain") && Object.op_Implicit((Object)(object)Player()))
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.IsOverallLoadingDone && !instance.IsGameplayPaused && GuardianEncounterStore.InvalidPayload == null)
			{
				GuardianEncounterStore.ForWorld(WorldUID())?.RegenerateOutsideArea(Time.deltaTime);
			}
		}
	}

	internal bool ResetGuardianAfterPartyDefeat(bool partyDefeated, string world)
	{
		if (!GuardianNetwork.Authority || !partyDefeated)
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)Boss) && (string.IsNullOrEmpty(Boss.PersistentWorldUID) || Boss.PersistentWorldUID == world))
		{
			if (!Boss.ResetForPartyDefeat())
			{
				return false;
			}
			CacheEncounter();
		}
		else
		{
			GuardianEncounterState guardianEncounterState = GuardianEncounterStore.ForWorld(world);
			if (guardianEncounterState == null || !guardianEncounterState.Valid() || guardianEncounterState.Health <= 0f || GuardianEncounterStore.InvalidPayload != null)
			{
				return false;
			}
			guardianEncounterState.Health = guardianEncounterState.MaximumHealth;
			guardianEncounterState.PlayerAggro = false;
			guardianEncounterState.TargetUID = null;
			guardianEncounterState.DisengagedFor = 0f;
			guardianEncounterState.Recovery = 2.4f;
		}
		SaveManager.Instance.SetSaveRequired();
		return true;
	}

	private void BindWorldSpawn()
	{
		worldSpawnEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("World", "Enabled", true, "Automatically spawn the unique Guardian at its fixed Chersonese location. A saved world defeat event permanently prevents its return.");
		GuardianWorldEvents.Install();
	}

	internal static string WorldUID()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)CharacterManager.Instance))
		{
			return null;
		}
		Character worldHostCharacter = CharacterManager.Instance.GetWorldHostCharacter();
		if (!Object.op_Implicit((Object)(object)worldHostCharacter) || !worldHostCharacter.IsWorldHost)
		{
			return null;
		}
		return UID.op_Implicit(worldHostCharacter.UID);
	}

	private void ResetWorldVisit()
	{
		activeWorldUID = null;
		worldSuppressed = (corpseSuppressed = false);
		nextWorldCheck = Time.realtimeSinceStartup + 2f;
	}

	private void TickWorldSpawn()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		if (Time.realtimeSinceStartup < nextWorldCheck)
		{
			return;
		}
		nextWorldCheck = Time.realtimeSinceStartup + 1f;
		CacheEncounter();
		Character val = Player();
		string text = WorldUID();
		if (!Object.op_Implicit((Object)(object)val) || !Authority() || string.IsNullOrEmpty(text))
		{
			return;
		}
		if (activeWorldUID != text)
		{
			if (Object.op_Implicit((Object)(object)Boss) || busy)
			{
				Despawn();
			}
			activeWorldUID = text;
			worldSuppressed = (corpseSuppressed = false);
		}
		bool flag = Object.op_Implicit((Object)(object)NetworkLevelLoader.Instance) && NetworkLevelLoader.Instance.IsOverallLoadingDone && Object.op_Implicit((Object)(object)QuestEventManager.Instance);
		bool defeated = flag && QuestEventManager.Instance.HasQuestEvent("local.val.leylineguardian.defeated.v1");
		if (worldSpawnEnabled.Value)
		{
			Scene activeScene = SceneManager.GetActiveScene();
			if (GuardianWorldRules.CanRestoreCorpse(((Scene)(ref activeScene)).name, flag, defeated, Object.op_Implicit((Object)(object)Boss) || busy || loading, corpseSuppressed))
			{
				((MonoBehaviour)this).StartCoroutine(Guard(SpawnWorldCorpse()));
				return;
			}
		}
		if (!worldSpawnEnabled.Value)
		{
			return;
		}
		Scene activeScene2 = SceneManager.GetActiveScene();
		if (!GuardianWorldRules.CanSpawn(((Scene)(ref activeScene2)).name, flag, defeated, Object.op_Implicit((Object)(object)Boss) || busy || loading, worldSuppressed) || GuardianEncounterStore.InvalidPayload != null)
		{
			return;
		}
		if (GuardianEncounterStore.ForWorld(text) == null)
		{
			Vector3 val2 = Vector3.ProjectOnPlane(((Component)val).transform.position - GuardianWorldRules.Position, Vector3.up);
			if (((Vector3)(ref val2)).sqrMagnitude < 25f)
			{
				return;
			}
		}
		((MonoBehaviour)this).StartCoroutine(Guard(SpawnWorld()));
	}

	private IEnumerator SpawnWorld()
	{
		Character player = Player();
		string world = WorldUID();
		if (!Object.op_Implicit((Object)(object)player) || !Authority() || !InGuardianArea || string.IsNullOrEmpty(world) || !Object.op_Implicit((Object)(object)QuestEventManager.Instance) || !Object.op_Implicit((Object)(object)NetworkLevelLoader.Instance) || !NetworkLevelLoader.Instance.IsOverallLoadingDone)
		{
			yield break;
		}
		CacheEncounter();
		GuardianEncounterState saved = GuardianEncounterStore.ForWorld(world);
		if (QuestEventManager.Instance.HasQuestEvent("local.val.leylineguardian.defeated.v1"))
		{
			if (Object.op_Implicit((Object)(object)Boss) && Boss.IsCorpse)
			{
				yield break;
			}
			IEnumerator corpse = SpawnWorldCorpse();
			try
			{
				while (corpse.MoveNext())
				{
					yield return corpse.Current;
				}
				yield break;
			}
			finally
			{
				((IDisposable)corpse).Dispose();
			}
		}
		if (GuardianEncounterStore.InvalidPayload != null)
		{
			yield break;
		}
		GuardianEncounterState resume = saved;
		if (resume != null && resume.Health <= 0f)
		{
			RecordWorldDefeat();
			IEnumerator corpse2 = SpawnWorldCorpse();
			try
			{
				while (corpse2.MoveNext())
				{
					yield return corpse2.Current;
				}
				yield break;
			}
			finally
			{
				((IDisposable)corpse2).Dispose();
			}
		}
		if (resume == null)
		{
			Vector3 val = Vector3.ProjectOnPlane(((Component)player).transform.position - GuardianWorldRules.Position, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 25f)
			{
				yield break;
			}
		}
		Vector3 point = resume?.Position ?? GuardianWorldRules.Position;
		float minimumNormal = ((resume != null) ? Mathf.Cos(0.9599311f) : 0.87f);
		RaycastHit ground = default(RaycastHit);
		if (!Physics.Raycast(point + Vector3.up * 3f, Vector3.down, ref ground, 8f, Global.FullEnvironmentMask, (QueryTriggerInteraction)1) || ((RaycastHit)(ref ground)).normal.y < minimumNormal - 0.001f)
		{
			nextWorldCheck = Time.realtimeSinceStartup + 8f;
			yield break;
		}
		point = ((RaycastHit)(ref ground)).point + Vector3.up * 0.03f;
		if (SpawnPlacement.Blockers(point, ((RaycastHit)(ref ground)).normal, Global.FullEnvironmentMask, (resume != null) ? 1.05f : 1.3f, 5.8f).Length > 0)
		{
			nextWorldCheck = Time.realtimeSinceStartup + 8f;
			yield break;
		}
		worldSuppressed = false;
		Quaternion rotation = ((resume != null) ? Quaternion.Euler(0f, resume.Yaw, 0f) : Quaternion.LookRotation(GuardianWorldRules.Forward));
		IEnumerator spawn = SpawnAt(point, rotation, world, resume);
		try
		{
			while (spawn.MoveNext())
			{
				yield return spawn.Current;
			}
		}
		finally
		{
			((IDisposable)spawn).Dispose();
		}
	}

	private IEnumerator SpawnWorldCorpse()
	{
		string world = WorldUID();
		if (!Object.op_Implicit((Object)(object)Player()) || !Authority() || !InGuardianArea || string.IsNullOrEmpty(world) || Object.op_Implicit((Object)(object)Boss) || busy || loading || !Object.op_Implicit((Object)(object)QuestEventManager.Instance) || !QuestEventManager.Instance.HasQuestEvent("local.val.leylineguardian.defeated.v1") || GuardianEncounterStore.InvalidPayload != null)
		{
			yield break;
		}
		GuardianEncounterState state = GuardianEncounterStore.ForWorld(world);
		if (state == null || state.Health > 0f)
		{
			GuardianEncounterState guardianEncounterState = new GuardianEncounterState
			{
				WorldUID = world,
				Position = (state?.Position ?? GuardianWorldRules.Position)
			};
			float yaw;
			if (state == null)
			{
				Quaternion val = Quaternion.LookRotation(GuardianWorldRules.Forward);
				yaw = ((Quaternion)(ref val)).eulerAngles.y;
			}
			else
			{
				yaw = state.Yaw;
			}
			guardianEncounterState.Yaw = yaw;
			guardianEncounterState.Health = 0f;
			guardianEncounterState.MaximumHealth = Health.Value;
			state = guardianEncounterState;
		}
		RaycastHit ground = default(RaycastHit);
		if (!Physics.Raycast(state.Position + Vector3.up * 3f, Vector3.down, ref ground, 8f, Global.FullEnvironmentMask, (QueryTriggerInteraction)1))
		{
			nextWorldCheck = Time.realtimeSinceStartup + 8f;
			yield break;
		}
		corpseSuppressed = false;
		IEnumerator spawn = SpawnAt(state.Position, Quaternion.Euler(0f, state.Yaw, 0f), world, state, corpse: true);
		try
		{
			while (spawn.MoveNext())
			{
				yield return spawn.Current;
			}
		}
		finally
		{
			((IDisposable)spawn).Dispose();
		}
	}

	internal void GuardianDefeated(GuardianBoss guardian)
	{
		if (GuardianWorldRules.IsPersistentDeath(guardian.PersistentWorldUID, WorldUID()))
		{
			CacheEncounter();
			RecordWorldDefeat();
		}
	}

	private void RecordWorldDefeat()
	{
		worldSuppressed = true;
		GuardianWorldEvents.Register();
		if (!Object.op_Implicit((Object)(object)QuestEventManager.Instance) || !QuestEventManager.Instance.AddEvent("local.val.leylineguardian.defeated.v1", 1, false))
		{
			throw new InvalidOperationException("Could not record Guardian's permanent defeat.");
		}
		SaveManager.Instance.SetSaveRequired();
	}

	private void RegisterLeylineWeapons()
	{
		leylineMace = WeaponTemplate(hammer: false);
		leylineHammer = WeaponTemplate(hammer: true);
		LeylineWeaponHits.Install();
		LeylineSmith.Install();
	}

	private SL_Weapon WeaponTemplate(bool hammer)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Expected O, but got Unknown
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Expected O, but got Unknown
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		SL_Weapon val = new SL_Weapon();
		((SL_Item)val).Target_ItemID = (hammer ? 2120110 : 2020100);
		((SL_Item)val).New_ItemID = (hammer ? 9024782 : 9024781);
		((SL_Item)val).Name = (hammer ? "Faultbreaker" : "Leyline Resonator");
		((SL_Item)val).IsUsable = false;
		((SL_Item)val).IsPickable = true;
		val.Unblockable = false;
		val.HealthLeechRatio = 0f;
		val.HealthBurnLeechRatio = 0f;
		val.IgnoreHalfResistances = false;
		((SL_Item)val).Description = (hammer ? "A heavy hammer built around the Guardian's glowing heart.\n\nFault Pulse: Special Attack releases a 4.5m shockwave that deals 24 damage, knocks enemies down and inflicts Pain. Direct hits also deal weapon damage. 12s cooldown." : "A runic mace forged around the Guardian's glowing heart.\n\nRunic Brand: Special Attack marks a foe. After 1.2s, the rune bursts for 18 Ethereal damage, knocks them down and inflicts Haunted. Arcs hit up to 3 nearby enemies for 12 damage each. 10s cooldown.");
		val.WeaponType = (WeaponType)(hammer ? 53 : 2);
		((SL_Item)val).EffectBehaviour = (EditBehaviours)2;
		SL_EffectTransform[] array = (SL_EffectTransform[])(object)new SL_EffectTransform[1];
		SL_EffectTransform val2 = new SL_EffectTransform();
		val2.TransformName = "Leyline ability hex";
		SL_Effect[] array2 = (SL_Effect[])(object)new SL_Effect[1];
		SL_AddStatusEffect val3 = new SL_AddStatusEffect();
		val3.StatusEffect = (hammer ? "Pain" : "Haunted");
		val3.ChanceToContract = 100;
		val3.AffectController = false;
		val3.NoDealer = false;
		((SL_Effect)val3).SyncType = (SyncTypes)0;
		((SL_Effect)val3).OverrideCategory = (EffectCategories)5;
		array2[0] = (SL_Effect)(object)val3;
		val2.Effects = array2;
		array[0] = val2;
		((SL_Item)val).EffectTransforms = array;
		SL_WeaponStats val4 = new SL_WeaponStats();
		((SL_ItemStats)val4).BaseValue = (hammer ? 650 : 550);
		((SL_ItemStats)val4).RawWeight = (hammer ? 8f : 5.5f);
		((SL_ItemStats)val4).MaxDurability = (hammer ? 350 : 275);
		val4.AttackSpeed = (hammer ? 0.9f : 1f);
		val4.Impact = (hammer ? 42 : 28);
		val4.StamCost = (hammer ? 6.9f : 4.8f);
		List<SL_Damage> list = new List<SL_Damage>();
		SL_Damage val5 = new SL_Damage();
		val5.Type = (Types)0;
		val5.Damage = (hammer ? 41.5f : 37f);
		list.Add(val5);
		SL_Damage val6 = new SL_Damage();
		val6.Type = (Types)1;
		val6.Damage = (hammer ? 7 : 5);
		list.Add(val6);
		val4.BaseDamage = list;
		((SL_Item)val).StatsHolder = (SL_ItemStats)(object)val4;
		SL_Weapon val7 = val;
		((SL_Item)val7).OnTemplateApplied += delegate(Item item)
		{
			ApplyWeaponAppearance(item, hammer);
		};
		return val7;
	}

	private void ApplyWeaponAppearance(Item item, bool hammer)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		AddStatusEffect[] componentsInChildren = ((Component)item).GetComponentsInChildren<AddStatusEffect>(true);
		foreach (AddStatusEffect obj in componentsInChildren)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(Effect), "m_effectType");
			EffectTypeSelector val = new EffectTypeSelector();
			val.SelectedEffectTypeName = "None";
			fieldInfo.SetValue(obj, val);
		}
		string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		ItemVisualsLink itemVisualLink = CustomItemVisuals.GetItemVisualLink(item);
		if (itemVisualLink == null || !Object.op_Implicit((Object)(object)itemVisualLink.ItemVisuals))
		{
			throw new InvalidOperationException("Crafted weapon has no cloned native visual");
		}
		LeylineWeaponArt.Build(itemVisualLink.ItemVisuals, hammer, directoryName);
		string path = Path.Combine(directoryName, hammer ? "leyline-faultbreaker-icon.png" : "leyline-resonator-icon.png");
		Sprite val2 = LeylineWeaponArt.LoadIcon(path);
		CustomItemVisuals.SetSpriteLink(item, val2, false);
		AccessTools.Field(typeof(Item), "m_itemIcon").SetValue(item, val2);
		item.ForceNonSavable = false;
	}

	private static void ValidateWeaponID(SL_Item template)
	{
		if (GuardianLootRules.Prefabs.TryGetValue(template.New_ItemID.ToString(), out var value) && Object.op_Implicit((Object)(object)value) && (Object)(object)value != (Object)(object)template.CurrentPrefab)
		{
			throw new InvalidOperationException("Crafted Guardian weapon item ID already occupied: " + template.New_ItemID);
		}
	}

	private void ApplyLeylineWeapons()
	{
		if (leylineMace == null || !CoreReady)
		{
			return;
		}
		int[] array = new int[4] { 2020100, 2120110, 6400110, 6200130 };
		foreach (int num in array)
		{
			if (!Object.op_Implicit((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(num)))
			{
				return;
			}
		}
		ValidateWeaponID((SL_Item)(object)leylineMace);
		ValidateWeaponID((SL_Item)(object)leylineHammer);
		if (!Object.op_Implicit((Object)(object)((SL_Item)leylineMace).CurrentPrefab))
		{
			((ContentTemplate)leylineMace).ApplyTemplate();
		}
		if (!Object.op_Implicit((Object)(object)((SL_Item)leylineHammer).CurrentPrefab))
		{
			((ContentTemplate)leylineHammer).ApplyTemplate();
		}
	}

	private void Awake()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		Instance = this;
		Health = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "Health", 1200f, new ConfigDescription("Guardian maximum health.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(100f, 20000f), new object[0]));
		Protection = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "Protection", 12f, new ConfigDescription("Guardian physical protection.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[0]));
		PhysicalDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "PhysicalDamage", 18f, (ConfigDescription)null);
		EtherealDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "EtherealDamage", 22f, (ConfigDescription)null);
		Impact = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "Impact", 45f, (ConfigDescription)null);
		BindDefenses();
		BindAudio();
		BindBarrage();
		BindRupture();
		BindCharge();
		BindBeam();
		BindUltimate();
		BindAI();
		BindWorldSpawn();
		RegisterLeylineWeapons();
		RegisterLeylineCore();
		RegisterBossTemplate();
		GuardianRelations.Install();
		network = new GuardianNetwork(this);
		SceneManager.activeSceneChanged += SceneChanged;
	}

	private void SceneChanged(Scene oldScene, Scene newScene)
	{
		if (Object.op_Implicit((Object)(object)AudioBus))
		{
			AudioBus.Silence();
		}
		Despawn();
		ResetWorldVisit();
		if (network != null)
		{
			network.Reset();
		}
	}

	internal void Failure(Exception e)
	{
		((BaseUnityPlugin)this).Logger.LogError((object)("Leyline Guardian: " + e));
	}

	internal static Character Player()
	{
		if (!Object.op_Implicit((Object)(object)CharacterManager.Instance))
		{
			return null;
		}
		Character firstLocalCharacter = CharacterManager.Instance.GetFirstLocalCharacter();
		if (!Object.op_Implicit((Object)(object)firstLocalCharacter) || !firstLocalCharacter.Alive || !firstLocalCharacter.IsStartInitDone || !firstLocalCharacter.IsLateInitDone || !((Component)firstLocalCharacter).gameObject.activeInHierarchy)
		{
			return null;
		}
		return firstLocalCharacter;
	}

	internal static bool Authority()
	{
		return GuardianNetwork.Authority;
	}

	private void Update()
	{
		if (Authority())
		{
			TickWorldSpawn();
			TickStoredEncounterRecovery();
		}
		if (network != null)
		{
			network.Tick();
		}
		if (busy && spawnDeadline > 0f && Time.realtimeSinceStartup > spawnDeadline)
		{
			Failure(new TimeoutException("Guardian initialization timed out"));
			Despawn();
		}
	}

	private IEnumerator Guard(IEnumerator routine)
	{
		try
		{
			while (true)
			{
				object current;
				try
				{
					if (!routine.MoveNext())
					{
						break;
					}
					current = routine.Current;
				}
				catch (Exception e)
				{
					Failure(e);
					Despawn();
					break;
				}
				yield return current;
			}
		}
		finally
		{
			if (routine is IDisposable disposable)
			{
				disposable.Dispose();
			}
		}
	}

	private void RegisterBossTemplate()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (template == null)
		{
			SL_Character val = new SL_Character();
			val.UID = "local.val.leylineguardian.template";
			val.Name = "Leyline Guardian";
			val.SaveType = (CharSaveType)0;
			val.Faction = (Factions)2;
			val.TargetableFactions = (Factions[])(object)new Factions[1] { (Factions)1 };
			val.Health = Health.Value;
			val.HealthRegen = 0f;
			val.ImpactResist = 80f;
			val.Protection = Protection.Value;
			val.Barrier = Barrier.Value;
			val.Damage_Resists = ResistanceValues();
			val.LootableOnDeath = true;
			val.DropPouchContents = true;
			val.DropWeapons = false;
			val.DestroyOnDeath = false;
			val.AutoTeleportWhenFar = false;
			val.ShouldSpawn = () => false;
			template = val;
			template.OnSpawn += OnSpawned;
			((ContentTemplate)template).ApplyTemplate();
		}
	}

	private IEnumerator SpawnAt(Vector3 point, Quaternion rotation, string worldUID, GuardianEncounterState resume = null, bool corpse = false)
	{
		//IL_000f: 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_0016: 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)
		Despawn();
		int request = generation;
		busy = true;
		pendingWorldUID = worldUID;
		pendingEncounter = resume;
		pendingCorpse = corpse;
		spawnDeadline = Time.realtimeSinceStartup + 90f;
		if (Asset == null)
		{
			loading = true;
			IEnumerator load = GuardianAsset.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), delegate(GuardianAsset a)
			{
				Asset = a;
			});
			try
			{
				while (load.MoveNext())
				{
					yield return load.Current;
				}
			}
			finally
			{
				loading = false;
				((IDisposable)load).Dispose();
			}
		}
		if (request != generation || !busy)
		{
			yield break;
		}
		if (!Object.op_Implicit((Object)(object)Player()) || !Authority() || (worldUID != null && (!InGuardianArea || WorldUID() != worldUID || !Object.op_Implicit((Object)(object)QuestEventManager.Instance) || (!corpse && QuestEventManager.Instance.HasQuestEvent("local.val.leylineguardian.defeated.v1")))))
		{
			Despawn();
			yield break;
		}
		RegisterBossTemplate();
		template.Health = Health.Value;
		template.Protection = Protection.Value;
		template.Barrier = Barrier.Value;
		template.Damage_Resists = ResistanceValues();
		spawnDeadline = Time.realtimeSinceStartup + 25f;
		pendingUID = "local.val.guardian." + Guid.NewGuid().ToString("N");
		spawning = template.Spawn(point, ((Quaternion)(ref rotation)).eulerAngles, pendingUID, (string)null);
		if (Object.op_Implicit((Object)(object)spawning))
		{
			yield break;
		}
		throw new InvalidOperationException("SideLoader returned no character.");
	}

	private void OnSpawned(Character character, string extra)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)character) && UID.op_Implicit(character.UID).StartsWith("local.val.guardian.", StringComparison.Ordinal))
		{
			if (!Authority())
			{
				((MonoBehaviour)this).StartCoroutine(Guard(FinishReplica(character)));
			}
			else if (busy && !(UID.op_Implicit(character.UID) != pendingUID))
			{
				spawning = character;
				((MonoBehaviour)this).StartCoroutine(Guard(FinishSpawn(character)));
			}
		}
	}

	private IEnumerator FinishSpawn(Character character)
	{
		yield return (object)new WaitForSeconds(1f);
		while (Object.op_Implicit((Object)(object)character) && busy && UID.op_Implicit(character.UID) == pendingUID && (!character.IsStartInitDone || !character.IsLateInitDone))
		{
			yield return null;
		}
		if (!Object.op_Implicit((Object)(object)character) || !busy || UID.op_Implicit(character.UID) != pendingUID)
		{
			yield break;
		}
		if (pendingWorldUID != null && (!InGuardianArea || WorldUID() != pendingWorldUID || !Object.op_Implicit((Object)(object)QuestEventManager.Instance) || (!pendingCorpse && QuestEventManager.Instance.HasQuestEvent("local.val.leylineguardian.defeated.v1"))))
		{
			Despawn();
			yield break;
		}
		GuardianBoss boss = (Boss = ((Component)character).gameObject.AddComponent<GuardianBoss>());
		boss.PersistentWorldUID = pendingWorldUID;
		boss.Initialize(character, Asset);
		if (pendingCorpse)
		{
			boss.RestoreCorpse(pendingEncounter);
		}
		else if (pendingEncounter != null)
		{
			boss.RestoreEncounter(pendingEncounter, GuardianCombatants.World());
		}
		busy = false;
		spawnDeadline = 0f;
		pendingEncounter = null;
		pendingCorpse = false;
	}

	internal void Despawn()
	{
		bool flag = Authority() && (!Object.op_Implicit((Object)(object)Boss) || !Boss.Replica);
		if (flag)
		{
			CacheEncounter();
		}
		generation++;
		pendingUID = null;
		pendingWorldUID = null;
		pendingEncounter = null;
		pendingCorpse = false;
		busy = false;
		spawnDeadline = 0f;
		Character val = (Object.op_Implicit((Object)(object)Boss) ? Boss.Character : spawning);
		if (Object.op_Implicit((Object)(object)Boss))
		{
			Boss.StopCombat();
		}
		Boss = null;
		spawning = null;
		if (Object.op_Implicit((Object)(object)val))
		{
			if (flag)
			{
				CustomCharacters.DestroyCharacterRPC(val);
			}
			else
			{
				GuardianNetwork.DestroyLocal(val);
			}
		}
	}

	private void OnDestroy()
	{
		if (network != null)
		{
			network.Dispose();
		}
		SL.OnPacksLoaded -= ApplyLeylineCore;
		LeylineWeaponHits.Remove();
		LeylineSmith.Remove();
		SceneManager.activeSceneChanged -= SceneChanged;
		Despawn();
		if (template != null)
		{
			template.OnSpawn -= OnSpawned;
			template.Unregister();
		}
		DisposeAudio();
		if (Asset != null)
		{
			Asset.Dispose();
		}
		GuardianRelations.Remove();
		GuardianWorldEvents.Remove();
		Instance = null;
	}

	private void BindRupture()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		RupturePhysical = ((BaseUnityPlugin)this).Config.Bind<float>("Rupture", "PhysicalDamage", 5f, new ConfigDescription("Physical damage per eruption before native defenses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		RuptureEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("Rupture", "EtherealDamage", 15f, new ConfigDescription("Ethereal damage per eruption before native defenses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		RuptureImpact = ((BaseUnityPlugin)this).Config.Bind<float>("Rupture", "Impact", 22f, new ConfigDescription("Native impact per eruption.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		RuptureCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Rupture", "Cooldown", 16f, new ConfigDescription("Seconds between autonomous Rupture casts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 60f), new object[0]));
	}

	private void BindUltimate()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Expected O, but got Unknown
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Expected O, but got Unknown
		UltimateEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "EtherealDamage", 36f, new ConfigDescription("Ethereal damage per orb projectile explosion before defenses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), new object[0]));
		UltimateLightning = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "LightningDamage", 12f, new ConfigDescription("Lightning damage per orb projectile explosion before defenses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), new object[0]));
		UltimateImpact = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "Impact", 35f, new ConfigDescription("Native impact per ultimate projectile.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		UltimateCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "Cooldown", 40f, new ConfigDescription("Ultimate cooldown; only available at or below 50 percent health.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 120f), new object[0]));
		FinaleEthereal = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "FinaleEtherealDamage", 140f, new ConfigDescription("Ethereal damage from the launched center orb's 9m explosion.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), new object[0]));
		FinaleLightning = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "FinaleLightningDamage", 60f, new ConfigDescription("Lightning damage from the launched center orb's explosion.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), new object[0]));
		FinaleImpact = ((BaseUnityPlugin)this).Config.Bind<float>("Ultimate", "FinaleImpact", 80f, new ConfigDescription("Native stability impact from the final orb explosion.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), new object[0]));
	}
}
public sealed class GuardianBoss : MonoBehaviour
{
	private BarrageAttack barrage;

	private readonly BarrageDamageLedger barrageHits = new BarrageDamageLedger();

	private int repeatAttack = 2;

	private Vector3 lastBarrageAim;

	private Vector3 barrageTargetVelocity;

	private readonly ChargeDamageLedger chargeHits = new ChargeDamageLedger();

	private readonly HashSet<Character> chargeKnockedTargets = new HashSet<Character>();

	private readonly ChargeSteering chargeSteering = new ChargeSteering();

	private TerrainWaveSurface chargeSurface;

	private TerrainClosePulse chargePulse;

	private ChargeFx chargeFx;

	private Vector3 chargeDirection;

	private Vector3 chargeOrigin;

	private bool chargeLocked;

	private bool chargeStopped;

	private bool chargeImpacted;

	private float chargeTravel;

	private float lastAutomaticCharge = -100f;

	private BeamEffects beamFx;

	private readonly BeamAim beamAim = new BeamAim();

	private readonly BeamPulseLedger beamHits = new BeamPulseLedger();

	private float lastAutomaticBeam = -100f;

	private bool beamActive;

	private Vector3 beamLastMuzzle;

	private GuardianNavigation navigation;

	private Vector3 home;

	public bool Autonomous = true;

	private float aiClock;

	private float nextAutomaticAttack;

	private float lastAutomaticSlam = -100f;

	private float lastAutomaticBarrage = -100f;

	private float hitFlash;

	private float lastAutomaticRupture = -100f;

	private int lastAutomaticRanged = 4;

	private string aiState = "Initializing";

	private float targetDistance;

	private bool targetVisible;

	private bool slamAccessible;

	private bool ruptureAccessible;

	private bool beamAccessible;

	private GuardianAttackAccess attackAccess;

	private float nextAccessScan;

	private Vector3 accessTarget;

	private Vector3 accessOrigin;

	private Quaternion accessFacing;

	private GuardianAudioBus sound;

	private AudioSource coreHum;

	private AudioSource rushSound;

	private AudioSource beamSound;

	private AudioSource beamContactSound;

	private AudioSource orbSound;

	private GuardianFootfall[] footsteps;

	private GuardianFootfall[] chargeFootsteps;

	private int soundClip = -1;

	private float nextPain;

	private bool deathSilent;

	private readonly bool[] ruptureSounds = new bool[3];

	private readonly bool[] ruptureWarnings = new bool[3];

	private Character combatTarget;

	private float nextTargetScan;

	private GuardianCorpsePose corpsePose;

	private ItemContainer corpsePouch;

	private int hurtboxLayer;

	private static readonly FieldInfo detectingField = typeof(MeleeWeapon).GetField("m_hitDetecting", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo alreadyHitField = typeof(Weapon).GetField("m_alreadyHitChars", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly MethodInfo bladeEndsMethod = typeof(MeleeWeapon).GetMethod("InitStartEnd", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo bladeStartField = typeof(MeleeWeapon).GetField("m_linecastStart", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo bladeTransformField = typeof(MeleeWeapon).GetField("m_linecastTrans", BindingFlags.Instance | BindingFlags.NonPublic);

	private readonly object[] bladeEnds = new object[2]
	{
		Vector3.zero,
		Vector3.zero
	};

	private GuardianLootInventory corpseLoot;

	private float disengagedFor;

	private GuardianPoseSampler networkPose;

	private GuardianFrame remote;

	private GuardianFrame prior;

	private GuardianCorpsePose previousPose;

	private GuardianCorpsePose targetPose;

	private float frameInterval = 0.0833333f;

	private int remoteClip = -1;

	private float remotePhase = -1f;

	private bool remoteStomp;

	private BeamTrace networkBeam;

	private readonly GuardianTurning turning = new GuardianTurning();

	private int pendingTurnAttack = -1;

	internal string PersistentWorldUID;

	public Character Character;

	internal bool Repeat;

	internal bool Replica;

	private GuardianModel model;

	private DeathCollapse deathCollapse;

	private GuardianAsset asset;

	private TerrainWaveSurface surface;

	private TerrainWaveEffects groundEffects;

	private TerrainWaveSurface closeSurface;

	private TerrainClosePulse closePulse;

	private Vector3 closeOrigin;

	private Vector3 anchor;

	private Quaternion facing;

	private bool ready;

	private bool dead;

	private bool stopped;

	private float idleTime;

	private float previousTime;

	private float lastHealth;

	private readonly HashSet<Character> hit = new HashSet<Character>();

	private readonly List<Hitbox> hurtboxes = new List<Hitbox>();

	private Renderer[] nativeRenderers;

	private Collider[] nativeColliders;

	private float nextRendererScan;

	private Light coreLight;

	private LockingPoint lockTarget;

	private DetectabilityEmitter detectionEmitter;

	private static readonly FieldInfo hitboxesField = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private RuptureAttack rupture;

	private readonly BarrageDamageLedger ruptureHits = new BarrageDamageLedger();

	private readonly UltimateFinaleLock ultimateLock = new UltimateFinaleLock();

	private float ultimateClock;

	private float ultimateAcceleration;

	private UltimateTracking ultimateTracking;

	private UltimateAttack ultimate;

	private UltimateEffects ultimateFx;

	private bool ultimateActive;

	private float lastUltimate = -100f;

	private Character ultimateAimTarget;

	private Vector3 ultimateLastAim;

	private Vector3 ultimateVelocity;

	private Vector3 ultimateFinalAim;

	private Vector3 ultimateFinalVelocity;

	private readonly BeamPulseLedger ultimateHits = new BeamPulseLedger();

	private Vector3 ChestSound
	{
		get
		{
			//IL_0035: 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_001f: 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)
			Transform val = model.Find("Leyline core");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return anchor + Vector3.up * 3f;
			}
			return val.position;
		}
	}

	internal bool IsCorpse => dead;

	internal static bool MeleeBridgeReady
	{
		get
		{
			if (detectingField != null && alreadyHitField != null && bladeEndsMethod != null && bladeStartField != null)
			{
				return bladeTransformField != null;
			}
			return false;
		}
	}

	internal bool NetworkReady
	{
		get
		{
			if (ready && !stopped && Object.op_Implicit((Object)(object)Character))
			{
				return Object.op_Implicit((Object)(object)model);
			}
			return false;
		}
	}

	internal int NetworkClip => model.ClipIndex;

	internal bool NetworkSettled
	{
		get
		{
			if (dead)
			{
				return model.TimeInClip >= asset.Clips[3].Duration;
			}
			return false;
		}
	}

	internal bool IsAttacking
	{
		get
		{
			if (Object.op_Implicit((Object)(object)model))
			{
				if (model.Clip