Decompiled source of BeyondTheWall v0.7.34

BeyondTheWall.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Mirror;
using Steamworks;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace BeyondTheWall;

[BepInPlugin("purp.bigwalk.beyondthewall", "Beyond The Wall", "0.7.34")]
public class Plugin : BasePlugin
{
	internal static ManualLogSource LogSource;

	public override void Load()
	{
		//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_0041: Expected O, but got Unknown
		LogSource = ((BasePlugin)this).Log;
		try
		{
			ClassInjector.RegisterTypeInIl2Cpp<ArgController>();
		}
		catch (Exception ex)
		{
			((BasePlugin)this).Log.LogError((object)("Could not register ArgController with IL2CPP: " + ex.Message));
			return;
		}
		try
		{
			GameObject val = new GameObject("BeyondTheWall_ARG");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<ArgController>();
			((BasePlugin)this).Log.LogInfo((object)"Beyond The Wall is listening.");
		}
		catch (Exception ex2)
		{
			((BasePlugin)this).Log.LogError((object)("Could not create ARG controller: " + ex2));
		}
	}
}
public class ArgController : MonoBehaviour
{
	private sealed class DissolvePart
	{
		public Renderer original;

		public bool hidden;

		public GameObject copy;

		public Mesh mesh;

		public readonly List<int[]> triangles = new List<int[]>();

		public readonly List<float[]> times = new List<float[]>();

		public float next;
	}

	private sealed class DissolveDigit
	{
		public Transform t;

		public Vector3 origin;

		public Vector3 velocity;

		public TextMesh text;

		public float delay;
	}

	private sealed class BossDissolve
	{
		public PlayerCharacter player;

		public uint serial;

		public float start;

		public float echoAt = 3.5f;

		public Vector3 position;

		public Vector3 bodyPosition;

		public Quaternion rotation;

		public Quaternion bodyRotation;

		public HostPhysicsSnapshot physics;

		public bool update;

		public bool late;

		public bool fixedUpdate;

		public bool cursor;

		public bool wasKinematic;

		public CursorLockMode cursorLock;

		public Camera camera;

		public Vector3 cameraPosition;

		public Quaternion cameraRotation;

		public GameObject root;

		public readonly List<DissolvePart> parts = new List<DissolvePart>();

		public readonly List<DissolveDigit> digits = new List<DissolveDigit>();

		public AudioSource voice;

		public AudioEchoFilter echo;

		public float volume;

		public bool ready;

		public float retry;

		public float visibilityScan;
	}

	private sealed class Peer
	{
		public ulong Nonce;

		public float Seen;

		public float RequestAt;

		public uint Actor;
	}

	private readonly EncounterProgress progress = new EncounterProgress();

	private GameObject noticedFigure;

	private GameObject thirdBell;

	private GameObject beyond;

	private readonly List<Renderer> beyondRenderers = new List<Renderer>();

	private float noticedTime;

	private float bellLookTime;

	private float nextLateAttempt;

	private float lastNoticeTick;

	private bool sightingCounted;

	private bool lateFailed;

	private string progressPath;

	private float nextEventAt;

	private float nextScanAt;

	private float eventEndAt;

	private float blackSpawnAt = -1f;

	private int blackConstructionRetries;

	private const int MaxBlackConstructionRetries = 3;

	private GameObject activeFigure;

	private Camera cam;

	private Random rng = new Random();

	private bool debugMenuOpen;

	private Material whiteMaterial;

	private Material blackMaterial;

	private bool gameplayArmed;

	private float nextGameplayProbeAt;

	private HashSet<string> alreadyLoggedObjectNames = new HashSet<string>();

	private int lastMainCameraId;

	private bool activeFigureIsDebug;

	private bool activeFigureIsNaturalWhite;

	private bool activeFigureIsNaturalBlack;

	private bool key6WasDown;

	private bool key1WasDown;

	private bool key2WasDown;

	private bool dreamSuspended;

	private const int VK_1 = 49;

	private const int VK_2 = 50;

	private const int VK_6 = 54;

	private const int VK_NUMPAD1 = 97;

	private const int VK_NUMPAD2 = 98;

	private const int VK_NUMPAD6 = 102;

	private Vector3 bossClearing;

	private Vector3 bossBodyRest;

	private Quaternion bossFacing = Quaternion.identity;

	private float bossFacingRadians;

	private bool bossClearingReady;

	private bool bossGroundReady;

	private float clearingRetry;

	private readonly Dictionary<Vector2, float> bossSurfaceCache = new Dictionary<Vector2, float>();

	private float floorRecoveryLogAt;

	private float arenaLayerRetry;

	private int addedArenaGroundBit;

	private PlayerCharacter arenaGroundPlayer;

	private readonly Transform[] attackUpper = (Transform[])(object)new Transform[2];

	private readonly Transform[] attackFore = (Transform[])(object)new Transform[2];

	private readonly Transform[] attackHands = (Transform[])(object)new Transform[2];

	private GameObject waveRoot;

	private readonly Transform[] waveSegments = (Transform[])(object)new Transform[64];

	private Material crystalDark;

	private Material crystalLight;

	private Material crystalCore;

	private Material warningFill;

	private Material warningEdge;

	private Mesh crystalMesh;

	private Mesh warningDisc;

	private Mesh warningRing;

	private Mesh warningSquare;

	private readonly GameObject[] bellHighlights = (GameObject[])(object)new GameObject[3];

	private const float ArenaDepth = 300f;

	private GameObject customArenaRoot;

	private int arenaCollisionLayer;

	private HostPhysicsSnapshot arenaReturnSnapshot;

	private Vector3 arenaArrivalPoint;

	private bool arenaReturned;

	private float returnRetry;

	private readonly Dictionary<ulong, BossDissolve> bossDissolves = new Dictionary<ulong, BossDissolve>();

	private AudioClip bossBellClip;

	private GameObject extraRoot;

	private readonly Transform[] extraMarks = (Transform[])(object)new Transform[3];

	private readonly Transform[] extraEffects = (Transform[])(object)new Transform[18];

	private GameObject laserRoot;

	private GameObject skyRipRoot;

	private Transform laserBeam;

	private Transform laserEye;

	private AudioClip finaleRoar;

	private readonly HashSet<ulong> arenaProtected = new HashSet<ulong>();

	private bool arenaArrived;

	private bool laserRoared;

	private float arrivalRetry;

	private readonly Queue<KeyValuePair<float, Vector3>> laserHistory = new Queue<KeyValuePair<float, Vector3>>();

	private Transform laserSheath;

	private Transform laserHalo;

	private Transform laserImpact;

	private Transform laserGuide;

	private readonly Transform[] laserCoils = (Transform[])(object)new Transform[48];

	private readonly Transform[] laserCharge = (Transform[])(object)new Transform[32];

	private readonly Transform[] laserSparks = (Transform[])(object)new Transform[24];

	private Light laserSourceLight;

	private Light laserImpactLight;

	private GameObject exitRift;

	private AudioSource bossAudio;

	private AudioClip bossClip;

	private bool bossMusicAttempted;

	private GameObject polishRoot;

	private readonly Transform[] bossFingers = (Transform[])(object)new Transform[20];

	private readonly Transform[] impactDebris = (Transform[])(object)new Transform[24];

	private readonly Transform[] riftRim = (Transform[])(object)new Transform[48];

	private Vector3 bossExitDirection;

	private GameObject riftRoot;

	private Transform riftOpening;

	private readonly Transform[] riftHazards = (Transform[])(object)new Transform[6];

	private readonly Transform[] riftWarnings = (Transform[])(object)new Transform[6];

	private AudioSource chaseAudio;

	private AudioClip chaseClip;

	private bool chaseStarted;

	private bool debugSpawningPaused;

	private bool debugLateHidden;

	private bool debugCursorOwned;

	private bool debugPreviousCursorVisible;

	private CursorLockMode debugPreviousCursorLock;

	private Texture2D debugRounded;

	private Texture2D debugEye;

	private GUIStyle debugButton;

	private GUIStyle debugLabel;

	private GUIStyle debugSmall;

	private Light fallbackSun;

	private Vector3 bellBearing;

	private Material finderMaterial;

	private bool lastFinderReveal;

	private float nextSunSearch;

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

	private float bossBellRetryAt;

	private ulong bossAimPlayer;

	private float bossAimRetryAt;

	private readonly Vector3[] bossBellPositions = (Vector3[])(object)new Vector3[3];

	private Transform finalWalk;

	private readonly List<Mesh> bossMeshes = new List<Mesh>();

	private GameObject bossRoot;

	private GameObject bossBody;

	private GameObject bossBarrier;

	private GameObject bossMark;

	private GameObject bossSweepMark;

	private readonly GameObject[] bossBells = (GameObject[])(object)new GameObject[3];

	private readonly List<Material> bossMaterials = new List<Material>();

	private readonly List<Transform> bossGlitchParts = new List<Transform>();

	private readonly List<Quaternion> bossRestRotations = new List<Quaternion>();

	private readonly List<Vector3> bossRestParts = new List<Vector3>();

	private readonly Dictionary<ulong, float> bossDead = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, float> bossGrace = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, uint> bossDeathEvents = new Dictionary<ulong, uint>();

	private int bossState;

	private int bossMask;

	private int bossAttack;

	private int bossCycle = -1;

	private int bossLastBellCycle = -1;

	private float bossEpoch;

	private float bossPhase;

	private float bossSearchAt;

	private float bossSendAt;

	private float bossReplicaAt;

	private float bossWonAt;

	private float bossRingAt;

	private Vector3 bossTarget;

	private uint bossDeathSerial;

	private bool bossEWasDown;

	private bool bossFailed;

	private bool bossEntryObserved;

	private string bossNotice = "";

	private PlayerCharacter capturedHost;

	private Corpse capturedCorpse;

	private HostPhysicsSnapshot capturedPhysics;

	private bool savedUpdate;

	private bool savedLate;

	private bool savedFixed;

	private bool savedKinematic;

	private bool savedGhost;

	private bool savedAudioGhost;

	private bool savedCursorVisible;

	private CursorLockMode savedCursorLock;

	private float capturedAt;

	private bool captureActive;

	private bool captureWasHost;

	private string returnNotice = "";

	private float nextReturnAttempt;

	private GameObject huntedFigure;

	private HuntState hunt;

	private bool wallReady;

	private float nextWallSearch;

	private Vector3 wallOrigin;

	private Vector3 wallOutward;

	private readonly List<Material> landmarkMaterials = new List<Material>();

	private readonly List<Mesh> landmarkMeshes = new List<Mesh>();

	private readonly List<Mesh> figureMeshes = new List<Mesh>();

	private readonly List<Material> figureMaterials = new List<Material>();

	private int renderAuditId;

	private float renderAuditAt;

	private bool renderAudited;

	private const int SharedChannel = 14731;

	private readonly Dictionary<ulong, Peer> sharedPeers = new Dictionary<ulong, Peer>();

	private readonly Dictionary<ulong, PlayerCharacter> sharedRoster = new Dictionary<ulong, PlayerCharacter>();

	private ulong sharedLocal;

	private ulong sharedHost;

	private ulong sharedAuthority;

	private ulong sharedNonce;

	private ulong sharedAuthorityNonce;

	private ulong sharedTarget;

	private uint sharedActor;

	private uint sharedSequence;

	private uint sharedEvent;

	private uint sharedLastSequence;

	private uint sharedCapturedEvent;

	private int sharedFigureInstance;

	private float sharedHelloAt;

	private float sharedSnapshotAt;

	private float sharedRosterAt;

	private float sharedReplicaExpires;

	private float sharedErrorAt;

	private SharedFrame replica;

	private bool BossLocalDead
	{
		get
		{
			if (bossDissolves.TryGetValue(sharedLocal, out var value) && (Object)(object)value.player != (Object)null)
			{
				return ((NetworkBehaviour)value.player).isLocalPlayer;
			}
			return false;
		}
	}

	private bool SpawningPaused
	{
		get
		{
			if (!SharedFollower)
			{
				return debugSpawningPaused;
			}
			if (replica != null)
			{
				return (replica.Request & 1) != 0;
			}
			return false;
		}
	}

	private bool LateEntitiesHidden
	{
		get
		{
			if (!SpawningPaused)
			{
				if (!SharedFollower)
				{
					return debugLateHidden;
				}
				if (replica != null)
				{
					return (replica.Request & 2) != 0;
				}
				return false;
			}
			return true;
		}
	}

	private bool BossArenaReady
	{
		get
		{
			if (bossBellReady[0] && bossBellReady[1])
			{
				return bossBellReady[2];
			}
			return false;
		}
	}

	private bool SharedFollower
	{
		get
		{
			if (sharedAuthority != 0L)
			{
				return sharedAuthority != sharedLocal;
			}
			return false;
		}
	}

	private bool SharedDriver => !SharedFollower;

	[DllImport("user32.dll")]
	private static extern short GetAsyncKeyState(int vKey);

	public ArgController(IntPtr ptr)
		: base(ptr)
	{
	}//IL_0038: 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)


	public void Start()
	{
		LoadChaseMusic();
		progressPath = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "BeyondTheWall.progress.txt");
		try
		{
			if (File.Exists(progressPath))
			{
				progress.Load(File.ReadAllText(progressPath));
			}
		}
		catch (Exception ex)
		{
			Plugin.LogSource.LogWarning((object)("Progress load: " + ex.Message));
		}
		lastNoticeTick = Time.time;
		nextEventAt = float.PositiveInfinity;
		nextScanAt = float.PositiveInfinity;
		nextGameplayProbeAt = Time.time + 2f;
		try
		{
			Camera main = Camera.main;
			lastMainCameraId = (((Object)(object)main != (Object)null) ? ((Object)main).GetInstanceID() : 0);
		}
		catch
		{
			lastMainCameraId = 0;
		}
	}

	public void Update()
	{
		TickShared();
		if (bossState == 1 && !BossLocalDead)
		{
			PollDebugKeysFallback();
		}
		if (TickFinalBoss())
		{
			return;
		}
		if (UpdateHostCapture())
		{
			SetDebugMenu(open: false);
			return;
		}
		bool flag = false;
		List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
		if (allPlayerCharacters != null)
		{
			for (int i = 0; i < allPlayerCharacters.Count; i++)
			{
				if ((Object)(object)allPlayerCharacters[i] != (Object)null && ((NetworkBehaviour)allPlayerCharacters[i]).isLocalPlayer)
				{
					flag = allPlayerCharacters[i].dreamer != null && allPlayerCharacters[i].dreamer.isDreaming;
					break;
				}
			}
		}
		if (flag)
		{
			if (!dreamSuspended)
			{
				ClearActiveFigure();
				ClearLateEntities();
				dreamSuspended = true;
			}
			lastNoticeTick = Time.time;
			return;
		}
		if (dreamSuspended)
		{
			dreamSuspended = false;
			ScheduleNextEvent(75f, 210f);
		}
		PollDebugKeysFallback();
		if (SpawningPaused)
		{
			lastNoticeTick = Time.time;
			return;
		}
		try
		{
			Camera main = Camera.main;
			int num = (((Object)(object)main != (Object)null) ? ((Object)main).GetInstanceID() : 0);
			if (num != lastMainCameraId)
			{
				lastMainCameraId = num;
				gameplayArmed = false;
				ClearActiveFigure();
				ClearLateEntities();
				nextEventAt = float.PositiveInfinity;
				nextScanAt = float.PositiveInfinity;
				nextGameplayProbeAt = Time.time + 1f;
				alreadyLoggedObjectNames.Clear();
				cam = main;
				if (Plugin.LogSource != null)
				{
					Plugin.LogSource.LogInfo((object)"ARG camera/scene transition detected; disarmed until gameplay is verified.");
				}
			}
		}
		catch
		{
		}
		if ((Object)(object)cam == (Object)null)
		{
			cam = Camera.main;
		}
		if (Time.time >= nextGameplayProbeAt)
		{
			nextGameplayProbeAt = Time.time + 15f;
			bool flag2 = LooksLikeGameplayScene();
			if (!gameplayArmed && flag2)
			{
				gameplayArmed = true;
				ScheduleNextEvent(45f, 100f);
				nextScanAt = Time.time + 10f;
				if (Plugin.LogSource != null)
				{
					Plugin.LogSource.LogInfo((object)"ARG gameplay scene armed.");
				}
			}
			else if (gameplayArmed && !flag2)
			{
				gameplayArmed = false;
				ClearActiveFigure();
				ClearLateEntities();
				nextEventAt = float.PositiveInfinity;
				nextScanAt = float.PositiveInfinity;
				if (Plugin.LogSource != null)
				{
					Plugin.LogSource.LogInfo((object)"ARG gameplay scene disarmed.");
				}
			}
		}
		float delta = Math.Max(0f, Math.Min(0.1f, Time.time - lastNoticeTick));
		lastNoticeTick = Time.time;
		if (gameplayArmed)
		{
			try
			{
				if (SharedDriver)
				{
					ObserveEncounter(delta);
				}
			}
			catch (Exception ex)
			{
				Plugin.LogSource.LogWarning((object)("Sighting check skipped: " + ex.Message));
				nextGameplayProbeAt = Time.time;
			}
			if (!lateFailed)
			{
				try
				{
					UpdateLateEntities(delta);
				}
				catch (Exception ex2)
				{
					lateFailed = true;
					ClearLateEntities();
					Plugin.LogSource.LogError((object)("Late entities disabled: " + ex2));
				}
			}
		}
		if ((Object)(object)activeFigure == (Object)null && (activeFigureIsDebug || activeFigureIsNaturalWhite || activeFigureIsNaturalBlack))
		{
			RecoverMissingFigure();
		}
		if ((Object)(object)activeFigure != (Object)null && Time.time >= eventEndAt)
		{
			EndActiveFigure();
		}
		AuditFigureRendering();
		if (SharedDriver)
		{
			UpdateHunt();
		}
		else
		{
			UpdateSharedReplica();
		}
		if (!gameplayArmed || SharedFollower)
		{
			return;
		}
		if (Time.time >= nextScanAt)
		{
			nextScanAt = Time.time + 120f;
			ScanIsland();
		}
		if (blackSpawnAt > 0f && Time.time >= blackSpawnAt)
		{
			if ((Object)(object)cam == (Object)null)
			{
				cam = Camera.main;
			}
			if ((Object)(object)cam == (Object)null || (Object)(object)activeFigure != (Object)null)
			{
				blackSpawnAt = Time.time + 0.5f;
			}
			else
			{
				blackSpawnAt = -1f;
				SpawnBlackOne();
			}
		}
		if ((Object)(object)activeFigure == (Object)null && blackSpawnAt <= 0f && Time.time >= nextEventAt)
		{
			BeginWhiteOneEvent();
		}
	}

	private bool PhysicalKeyDown(int mainKey, int numpadKey)
	{
		try
		{
			return (GetAsyncKeyState(mainKey) & 0x8000) != 0 || (GetAsyncKeyState(numpadKey) & 0x8000) != 0;
		}
		catch
		{
			return false;
		}
	}

	private void PollDebugKeysFallback()
	{
		if (!Application.isFocused)
		{
			return;
		}
		bool flag = PhysicalKeyDown(54, 102);
		bool flag2 = PhysicalKeyDown(49, 97);
		bool flag3 = PhysicalKeyDown(50, 98);
		if (flag && !key6WasDown)
		{
			SetDebugMenu(!debugMenuOpen);
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogInfo((object)(debugMenuOpen ? "DEBUG MENU OPEN" : "DEBUG MENU CLOSED"));
			}
		}
		if (debugMenuOpen)
		{
			if (flag2 && !key1WasDown)
			{
				DebugSpawnWhiteOne();
			}
			if (flag3 && !key2WasDown)
			{
				DebugSpawnBlackOne();
			}
		}
		key6WasDown = flag;
		key1WasDown = flag2;
		key2WasDown = flag3;
	}

	public void OnGUI()
	{
		DrawFinalBoss();
		if (!BossLocalDead && !DrawHostCapture() && debugMenuOpen)
		{
			DrawBentleyMenu();
		}
	}

	private void PrepareForDebugSpawn()
	{
		if ((Object)(object)activeFigure != (Object)null && activeFigureIsNaturalWhite)
		{
			if (gameplayArmed)
			{
				ScheduleNextEvent(75f, 210f);
			}
			else
			{
				nextEventAt = float.PositiveInfinity;
			}
		}
		if ((Object)(object)activeFigure != (Object)null && activeFigureIsNaturalBlack)
		{
			blackConstructionRetries = 0;
			blackSpawnAt = (gameplayArmed ? (Time.time + 0.5f) : (-1f));
		}
		ClearFigureOnly();
	}

	private bool TryFindNearbyDebugSpawn(float groundOffset, out Vector3 position, bool white = false)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_00a5: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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_0100: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: 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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		if ((Object)(object)cam == (Object)null)
		{
			cam = Camera.main;
		}
		if ((Object)(object)cam == (Object)null)
		{
			return false;
		}
		Vector3 position2 = ((Component)cam).transform.position;
		Vector3 val = default(Vector3);
		RaycastHit val2 = default(RaycastHit);
		Vector3 val4 = default(Vector3);
		RaycastHit val5 = default(RaycastHit);
		for (int i = 0; i < 18; i++)
		{
			float num = (float)(rng.NextDouble() * Math.PI * 2.0);
			float num2 = 3f + (float)rng.NextDouble() * 7f;
			((Vector3)(ref val))..ctor(position2.x + (float)Math.Cos(num) * num2, position2.y + 2f, position2.z + (float)Math.Sin(num) * num2);
			if (!Physics.Raycast(val + Vector3.up * 4f, Vector3.down, ref val2, 12f, -1, (QueryTriggerInteraction)1))
			{
				continue;
			}
			val = ((RaycastHit)(ref val2)).point + Vector3.up * groundOffset;
			if (white && !WhiteSideOfWall(val))
			{
				continue;
			}
			Vector3 val3 = val + Vector3.up * 1.25f - position2;
			float num3 = (float)Math.Sqrt(val3.x * val3.x + val3.y * val3.y + val3.z * val3.z);
			if (!(num3 < 0.01f))
			{
				((Vector3)(ref val4))..ctor(val3.x / num3, val3.y / num3, val3.z / num3);
				if (!Physics.Raycast(position2, val4, ref val5, Math.Max(0.1f, num3 - 0.35f), -1, (QueryTriggerInteraction)1))
				{
					position = val;
					return true;
				}
			}
		}
		return false;
	}

	private void DebugSpawnWhiteOne()
	{
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		if (SpawningPaused)
		{
			return;
		}
		debugLateHidden = false;
		if (RequestSharedSpawn(1))
		{
			return;
		}
		if ((Object)(object)cam == (Object)null)
		{
			cam = Camera.main;
		}
		if ((Object)(object)cam == (Object)null)
		{
			return;
		}
		PrepareForDebugSpawn();
		try
		{
			activeFigure = BuildFigure("The White One", white: true);
			activeFigureIsDebug = true;
			activeFigureIsNaturalWhite = false;
			activeFigureIsNaturalBlack = false;
		}
		catch (Exception ex)
		{
			activeFigure = null;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("White One debug spawn skipped: " + ex.Message));
			}
			return;
		}
		if ((Object)(object)activeFigure == (Object)null)
		{
			activeFigureIsDebug = false;
			return;
		}
		try
		{
			if (!TryFindNearbyDebugSpawn(0.6f, out var position, white: true))
			{
				AbortSpawnedFigure();
				if (Plugin.LogSource != null)
				{
					Plugin.LogSource.LogWarning((object)"DEBUG: could not find a clear nearby spawn point for The White One.");
				}
				return;
			}
			activeFigure.transform.position = position;
			FaceCamera(activeFigure);
			eventEndAt = Time.time + 12f;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogInfo((object)"DEBUG: spawned The White One within 10m.");
			}
		}
		catch (Exception ex2)
		{
			AbortSpawnedFigure();
			cam = null;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("White One debug placement aborted: " + ex2.Message));
			}
		}
	}

	private void DebugSpawnBlackOne()
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		if (SpawningPaused)
		{
			return;
		}
		debugLateHidden = false;
		if (RequestSharedSpawn(2))
		{
			return;
		}
		if ((Object)(object)cam == (Object)null)
		{
			cam = Camera.main;
		}
		if ((Object)(object)cam == (Object)null)
		{
			return;
		}
		PrepareForDebugSpawn();
		try
		{
			activeFigure = BuildFigure("The Black One", white: false);
			activeFigureIsDebug = true;
			activeFigureIsNaturalWhite = false;
			activeFigureIsNaturalBlack = false;
		}
		catch (Exception ex)
		{
			activeFigure = null;
			activeFigureIsDebug = false;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("Black One spawn skipped: " + ex.Message));
			}
			return;
		}
		if ((Object)(object)activeFigure == (Object)null)
		{
			activeFigureIsDebug = false;
			return;
		}
		try
		{
			if (!TryFindNearbyDebugSpawn(0.03f, out var position))
			{
				AbortSpawnedFigure();
				if (Plugin.LogSource != null)
				{
					Plugin.LogSource.LogWarning((object)"DEBUG: could not find a clear nearby spawn point for The Black One.");
				}
				return;
			}
			activeFigure.transform.position = position;
			activeFigure.transform.localScale = new Vector3(0.68f, 1.85f, 0.68f);
			FaceCamera(activeFigure);
			BeginHunt();
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogInfo((object)"DEBUG: spawned The Black One within 10m.");
			}
		}
		catch (Exception ex2)
		{
			AbortSpawnedFigure();
			cam = null;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("Black One debug placement aborted: " + ex2.Message));
			}
		}
	}

	private void AbortSpawnedFigure()
	{
		StopChaseMusic();
		noticedFigure = null;
		noticedTime = 0f;
		sightingCounted = false;
		eventEndAt = 0f;
		if ((Object)(object)activeFigure != (Object)null)
		{
			DestroyFigure(activeFigure);
		}
		activeFigure = null;
		activeFigureIsDebug = false;
		activeFigureIsNaturalWhite = false;
		activeFigureIsNaturalBlack = false;
	}

	private void ClearFigureOnly()
	{
		StopChaseMusic();
		noticedFigure = null;
		noticedTime = 0f;
		sightingCounted = false;
		eventEndAt = 0f;
		if ((Object)(object)activeFigure != (Object)null)
		{
			DestroyFigure(activeFigure);
		}
		activeFigure = null;
		activeFigureIsDebug = false;
		activeFigureIsNaturalWhite = false;
		activeFigureIsNaturalBlack = false;
	}

	private void ClearActiveFigure()
	{
		blackSpawnAt = -1f;
		blackConstructionRetries = 0;
		ClearFigureOnly();
	}

	private List<GameObject> FindAllGameObjectsSafe()
	{
		List<GameObject> list = new List<GameObject>();
		try
		{
			MethodInfo[] methods = typeof(Resources).GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo == null || methodInfo.Name != "FindObjectsOfTypeAll" || !methodInfo.IsGenericMethodDefinition || methodInfo.GetGenericArguments().Length != 1 || methodInfo.GetParameters().Length != 0)
				{
					continue;
				}
				try
				{
					if (!(methodInfo.MakeGenericMethod(typeof(GameObject)).Invoke(null, null) is IEnumerable enumerable))
					{
						continue;
					}
					foreach (object item in enumerable)
					{
						GameObject val = (GameObject)((item is GameObject) ? item : null);
						if ((Object)(object)val != (Object)null)
						{
							list.Add(val);
						}
					}
					if (list.Count <= 0)
					{
						continue;
					}
					return list;
				}
				catch
				{
				}
			}
		}
		catch
		{
		}
		return list;
	}

	private bool LooksLikeGameplayScene()
	{
		try
		{
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return false;
			}
			List<GameObject> list = FindAllGameObjectsSafe();
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				GameObject val = list[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool activeInHierarchy;
				string name;
				try
				{
					activeInHierarchy = val.activeInHierarchy;
					name = ((Object)val).name;
				}
				catch
				{
					continue;
				}
				if (!activeInHierarchy)
				{
					continue;
				}
				num++;
				if (!string.IsNullOrEmpty(name))
				{
					string text = name.ToLowerInvariant();
					if (text.Contains("gourd") || text.Contains("puzzle") || text.Contains("bell") || text.Contains("train") || text.Contains("tram") || text.Contains("bird") || text.Contains("player"))
					{
						return true;
					}
					if ((text.Contains("mainmenu") || text.Contains("titlemenu") || text.Contains("loading") || text.Contains("boot")) && num < 40)
					{
						return false;
					}
				}
			}
			if (list.Count == 0)
			{
				string text2 = "";
				try
				{
					text2 = (((Object)(object)((Component)main).gameObject != (Object)null) ? ((Object)((Component)main).gameObject).name.ToLowerInvariant() : "");
				}
				catch
				{
				}
				if (text2.Contains("menu") || text2.Contains("title") || text2.Contains("loading") || text2.Contains("boot"))
				{
					return false;
				}
				return true;
			}
			return num >= 40;
		}
		catch (Exception ex)
		{
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("Gameplay probe skipped: " + ex.Message));
			}
			return gameplayArmed;
		}
	}

	private Vector3 PutOnGround(Vector3 position, float fallbackYOffset, float footClearance)
	{
		//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_000b: 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_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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = position + Vector3.up * 20f;
		try
		{
			int num = -5;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 80f, num, (QueryTriggerInteraction)1))
			{
				position.y = ((RaycastHit)(ref val2)).point.y + footClearance;
				return position;
			}
		}
		catch
		{
		}
		position.y = (((Object)(object)cam != (Object)null) ? (((Component)cam).transform.position.y + fallbackYOffset + footClearance) : (position.y + footClearance));
		return position;
	}

	public void OnDestroy()
	{
		ResetFinalBoss();
		if ((Object)(object)bossBellClip != (Object)null)
		{
			Object.Destroy((Object)(object)bossBellClip);
		}
		DisposeDebugMenu();
		DisposeChaseMusic();
		ReleaseHost(force: true);
		ClearActiveFigure();
		ClearLateEntities();
		if ((Object)(object)whiteMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)whiteMaterial);
		}
		if ((Object)(object)blackMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)blackMaterial);
		}
		whiteMaterial = null;
		blackMaterial = null;
	}

	private void ScheduleNextEvent(float minSeconds, float maxSeconds)
	{
		float num = (float)rng.NextDouble();
		nextEventAt = Time.time + minSeconds + (maxSeconds - minSeconds) * num;
	}

	private void BeginWhiteOneEvent()
	{
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		debugLateHidden = false;
		if (blackSpawnAt > 0f)
		{
			return;
		}
		if ((Object)(object)cam == (Object)null)
		{
			ScheduleNextEvent(20f, 40f);
			return;
		}
		try
		{
			activeFigure = BuildFigure("The White One", white: true);
			activeFigureIsDebug = false;
			activeFigureIsNaturalWhite = true;
			activeFigureIsNaturalBlack = false;
		}
		catch (Exception ex)
		{
			activeFigure = null;
			activeFigureIsDebug = false;
			activeFigureIsNaturalWhite = false;
			ScheduleNextEvent(20f, 40f);
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("White One spawn skipped: " + ex.Message));
			}
			return;
		}
		if ((Object)(object)activeFigure == (Object)null)
		{
			activeFigureIsDebug = false;
			activeFigureIsNaturalWhite = false;
			ScheduleNextEvent(20f, 40f);
			return;
		}
		try
		{
			if (!TryNaturalPosition(28f, 52f, 0.6f, out var point, white: true))
			{
				AbortSpawnedFigure();
				ScheduleNextEvent(25f, 45f);
				return;
			}
			if (rng.Next(0, 100) < 2)
			{
				point.y += 6.5f;
			}
			activeFigure.transform.position = point;
			FaceCamera(activeFigure);
			eventEndAt = Time.time + 12f;
			if (progress.White >= 2 && rng.Next(0, 100) < 30)
			{
				blackConstructionRetries = 0;
				blackSpawnAt = eventEndAt + 0.25f + (float)rng.NextDouble() * 1.5f;
			}
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogInfo((object)"???");
			}
		}
		catch (Exception ex2)
		{
			AbortSpawnedFigure();
			cam = null;
			ScheduleNextEvent(20f, 40f);
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("White One placement aborted: " + ex2.Message));
			}
		}
	}

	private void RetryOrAbandonBlackOne(string reason)
	{
		blackConstructionRetries++;
		if (gameplayArmed && blackConstructionRetries <= 3)
		{
			blackSpawnAt = Time.time + 1f;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("Black One spawn retry " + blackConstructionRetries + "/" + 3 + ": " + reason));
			}
		}
		else
		{
			blackSpawnAt = -1f;
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("Black One spawn abandoned after " + blackConstructionRetries + " construction failures: " + reason));
			}
			blackConstructionRetries = 0;
		}
	}

	private void SpawnBlackOne()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cam == (Object)null || (Object)(object)activeFigure != (Object)null)
		{
			return;
		}
		try
		{
			activeFigure = BuildFigure("The Black One", white: false);
			activeFigureIsDebug = false;
			activeFigureIsNaturalWhite = false;
			activeFigureIsNaturalBlack = true;
		}
		catch (Exception ex)
		{
			activeFigure = null;
			activeFigureIsNaturalBlack = false;
			RetryOrAbandonBlackOne("construction exception: " + ex.Message);
			return;
		}
		if ((Object)(object)activeFigure == (Object)null)
		{
			activeFigureIsNaturalBlack = false;
			RetryOrAbandonBlackOne("figure construction returned null");
			return;
		}
		blackConstructionRetries = 0;
		try
		{
			if (!TryNaturalPosition(34f, 56f, 0.03f, out var point))
			{
				AbortSpawnedFigure();
				RetryOrAbandonBlackOne("no clear grounded position");
				return;
			}
			activeFigure.transform.position = point;
			activeFigure.transform.localScale = new Vector3(0.68f, 1.85f, 0.68f);
			FaceCamera(activeFigure);
			BeginHunt();
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogInfo((object)"???");
			}
		}
		catch (Exception ex2)
		{
			AbortSpawnedFigure();
			cam = null;
			RetryOrAbandonBlackOne("placement exception: " + ex2.Message);
		}
	}

	private GameObject BuildFigure(string name, bool white)
	{
		return BuildPlayerFigure(name, white);
	}

	private Material MakeMaterial(Color color)
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		Shader val = Shader.Find("Unlit/Color");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Sprites/Default");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("UI/Default");
		}
		if ((Object)(object)val == (Object)null)
		{
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)"No usable shader found for ARG figure.");
			}
			return null;
		}
		return new Material(val)
		{
			color = color
		};
	}

	private void ApplyMaterial(GameObject go, Material mat)
	{
		Renderer component = go.GetComponent<Renderer>();
		if ((Object)(object)component != (Object)null && (Object)(object)mat != (Object)null)
		{
			component.sharedMaterial = mat;
		}
	}

	private void RemoveCollider(GameObject go)
	{
		Collider component = go.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			component.enabled = false;
			Object.Destroy((Object)(object)component);
		}
	}

	private void FaceCamera(GameObject go)
	{
		//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_0028: 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)
		if (!((Object)(object)cam == (Object)null))
		{
			Vector3 position = ((Component)cam).transform.position;
			position.y = go.transform.position.y + 1.5f;
			go.transform.LookAt(position);
		}
	}

	private void RecoverMissingFigure()
	{
		ClearFigureMeshes();
		bool num = activeFigureIsDebug;
		bool flag = activeFigureIsNaturalWhite;
		bool flag2 = activeFigureIsNaturalBlack;
		activeFigure = null;
		activeFigureIsDebug = false;
		activeFigureIsNaturalWhite = false;
		activeFigureIsNaturalBlack = false;
		noticedFigure = null;
		noticedTime = 0f;
		sightingCounted = false;
		eventEndAt = 0f;
		if (num)
		{
			return;
		}
		if (flag)
		{
			if (gameplayArmed)
			{
				ScheduleNextEvent(75f, 210f);
			}
			else
			{
				nextEventAt = float.PositiveInfinity;
			}
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)"Natural White figure vanished externally; ARG state recovered.");
			}
		}
		else if (flag2 && Plugin.LogSource != null)
		{
			Plugin.LogSource.LogWarning((object)"Natural Black figure vanished externally; ARG state recovered.");
		}
	}

	private void EndActiveFigure()
	{
		StopChaseMusic();
		ClearFigureMeshes();
		bool num = activeFigureIsDebug;
		bool flag = activeFigureIsNaturalWhite;
		if ((Object)(object)activeFigure != (Object)null)
		{
			DestroyFigure(activeFigure);
		}
		activeFigure = null;
		activeFigureIsDebug = false;
		activeFigureIsNaturalWhite = false;
		activeFigureIsNaturalBlack = false;
		noticedFigure = null;
		noticedTime = 0f;
		sightingCounted = false;
		eventEndAt = 0f;
		if (!num && flag)
		{
			if (gameplayArmed)
			{
				ScheduleNextEvent(75f, 210f);
			}
			else
			{
				nextEventAt = float.PositiveInfinity;
			}
		}
	}

	private void ScanIsland()
	{
		try
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			HashSet<string> hashSet = new HashSet<string>();
			List<GameObject> list = FindAllGameObjectsSafe();
			for (int i = 0; i < list.Count; i++)
			{
				GameObject val = list[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool activeInHierarchy;
				string name;
				try
				{
					activeInHierarchy = val.activeInHierarchy;
					name = ((Object)val).name;
				}
				catch
				{
					continue;
				}
				if (activeInHierarchy && !string.IsNullOrEmpty(name))
				{
					string text = name.ToLowerInvariant();
					bool flag = false;
					if (text.Contains("ball"))
					{
						num++;
						flag = true;
					}
					if (text.Contains("bell"))
					{
						num2++;
						flag = true;
					}
					if (text.Contains("lantern") || text.Contains("lamp"))
					{
						num3++;
						flag = true;
					}
					if (text.Contains("puzzle"))
					{
						num4++;
						flag = true;
					}
					if (text.Contains("gourd"))
					{
						num5++;
						flag = true;
					}
					if (flag && hashSet.Count < 80 && !alreadyLoggedObjectNames.Contains(name))
					{
						hashSet.Add(name);
					}
				}
			}
			if (Plugin.LogSource == null)
			{
				return;
			}
			Plugin.LogSource.LogInfo((object)("??? ball=" + num + " bell=" + num2 + " lantern=" + num3 + " puzzle=" + num4 + " gourd=" + num5));
			foreach (string item in hashSet)
			{
				alreadyLoggedObjectNames.Add(item);
				Plugin.LogSource.LogInfo((object)("??? object=" + item));
			}
		}
		catch (Exception ex)
		{
			if (Plugin.LogSource != null)
			{
				Plugin.LogSource.LogWarning((object)("ARG scene scan skipped: " + ex.Message));
			}
		}
	}

	private unsafe bool FindBossClearing()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: 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_015b: 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_0180: 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_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		if (bossClearingReady)
		{
			return true;
		}
		if (Time.unscaledTime < clearingRetry)
		{
			return false;
		}
		clearingRetry = Time.unscaledTime + 3f;
		float num = float.MaxValue;
		Vector3 val = Vector3.zero;
		_ = Vector3.zero;
		for (int i = 80; i <= 420; i += 20)
		{
			for (int j = -120; j <= 120; j += 20)
			{
				Vector3 val2 = wallOrigin + wallOutward * (float)i + finalWalk.right * (float)j;
				if (!BossFloor(val2 + Vector3.up * 180f, 360f, out var point) || !FinalBossRules.DryArenaHeight(point.y))
				{
					continue;
				}
				float num2 = 0f;
				bool flag = true;
				for (int k = 0; k < 8; k++)
				{
					float num3 = (float)k * (float)Math.PI / 4f;
					Vector3 val3 = point + (finalWalk.right * Mathf.Cos(num3) + finalWalk.forward * Mathf.Sin(num3)) * 22f;
					if (!BossFloor(val3 + Vector3.up * 12f, 24f, out var point2) || !FinalBossRules.DryArenaHeight(point2.y) || Mathf.Abs(point2.y - point.y) > 3f)
					{
						flag = false;
						break;
					}
					num2 += Mathf.Abs(point2.y - point.y);
					foreach (Collider item in (Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(point2 + Vector3.up * 2f, 1.3f, -1, (QueryTriggerInteraction)1))
					{
						if ((Object)(object)item != (Object)null && (Object)(object)item.attachedRigidbody == (Object)null)
						{
							flag = false;
							break;
						}
					}
					if (!flag)
					{
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
				for (int l = -16; l <= 16 && flag; l += 8)
				{
					for (int m = -16; m <= 16; m += 8)
					{
						Vector3 val4 = point + finalWalk.right * (float)l + finalWalk.forward * (float)m;
						if (!BossFloor(val4 + Vector3.up * 12f, 24f, out var point3) || !FinalBossRules.DryArenaHeight(point3.y) || Mathf.Abs(point3.y - point.y) > 3f)
						{
							flag = false;
							break;
						}
						foreach (Collider item2 in (Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(point3 + Vector3.up * 2f, 1.3f, -1, (QueryTriggerInteraction)1))
						{
							if ((Object)(object)item2 != (Object)null && (Object)(object)item2.attachedRigidbody == (Object)null)
							{
								flag = false;
								break;
							}
						}
						if (!flag)
						{
							break;
						}
					}
				}
				if (flag)
				{
					Vector3 val5 = point;
					float num4 = num2 * 20f + (float)Mathf.Abs(i - 200) * 0.12f + (float)Mathf.Abs(j) * 0.1f;
					if (num4 < num)
					{
						num = num4;
						val = point;
					}
				}
			}
		}
		if (num == float.MaxValue)
		{
			return false;
		}
		bossClearing = val - Vector3.up * 300f;
		Vector3 val6 = bossClearing;
		bossBodyRest = finalWalk.InverseTransformPoint(val6 + Vector3.up * 16f);
		bossClearingReady = true;
		ManualLogSource logSource = Plugin.LogSource;
		Vector3 val7 = bossClearing;
		string? text = ((object)(*(Vector3*)(&val7))/*cast due to .constrained prefix*/).ToString();
		val7 = val6;
		logSource.LogInfo((object)("Boss clearing selected beyond wall: " + text + "; grounded body: " + ((object)(*(Vector3*)(&val7))/*cast due to .constrained prefix*/).ToString()));
		return true;
	}

	private bool FindAttackGround(Vector3 target, int attack, out Vector3 floor)
	{
		//IL_0000: 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_001f: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: 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_0143: Unknown result type (might be due to invalid IL or missing references)
		float num = FinalBossRules.AttackProbeTop(target.y, bossClearing.y);
		if (!BossFloor(new Vector3(target.x, num, target.z), FinalBossRules.AttackProbeDepth(target.y, bossClearing.y), out floor) || !ArenaFloorHeight(floor.y))
		{
			return false;
		}
		float num2 = attack switch
		{
			3 => 1.2f, 
			2 => 6f, 
			0 => 3f, 
			4 => 3.6f, 
			_ => 2.1f, 
		};
		float num3 = attack switch
		{
			5 => 4.1f, 
			4 => 6.3f, 
			2 => 6f, 
			7 => 12f, 
			1 => 9f, 
			_ => 3f, 
		};
		for (int i = -2; i <= 2; i++)
		{
			for (int j = -4; j <= 4; j++)
			{
				Vector3 val = floor + finalWalk.right * ((float)i * num2 / 2f) + finalWalk.forward * ((float)j * num3 / 4f);
				if (!BossFloor(val + Vector3.up * 4f, 8f, out var point) || !FinalBossRules.TerrainSupportedHeight(point.y - floor.y))
				{
					return false;
				}
			}
		}
		return true;
	}

	private Vector3 BossSurface(Vector3 point)
	{
		//IL_0002: 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_003b: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(Mathf.Round(point.x * 4f) / 4f, Mathf.Round(point.z * 4f) / 4f);
		if (!bossSurfaceCache.TryGetValue(val, out var value))
		{
			Vector3 origin = default(Vector3);
			((Vector3)(ref origin))..ctor(val.x, bossTarget.y + 4f, val.y);
			value = ((BossFloor(origin, 8f, out var point2) && FinalBossRules.TerrainSupportedHeight(point2.y - bossTarget.y)) ? point2.y : bossTarget.y);
			if (bossSurfaceCache.Count > 8192)
			{
				bossSurfaceCache.Clear();
			}
			bossSurfaceCache[val] = value;
		}
		return new Vector3(point.x, value, point.z);
	}

	private bool BossTerrainHit(PlayerCharacter player)
	{
		//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_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: 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_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: 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_00d0: 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_00da: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)player).transform.position;
		Vector3 val = finalWalk.InverseTransformDirection(position - bossTarget);
		if (bossAttack >= 6)
		{
			if (bossPhase < 1.8f || bossPhase >= FinalBossRules.AttackEnd(bossAttack))
			{
				return false;
			}
			for (int i = 0; i < 6; i++)
			{
				if (FinalBossRules.HazardPresent(bossAttack, i, bossPhase))
				{
					float num = FinalBossRules.HazardX(bossAttack, i, bossPhase);
					float num2 = FinalBossRules.HazardZ(bossAttack, i, bossPhase);
					Vector3 val2 = BossSurface(bossTarget + finalWalk.right * num + finalWalk.forward * num2);
					if (FinalBossRules.OrbTouches(val.x - num, val.z - num2, FinalBossRules.HazardY(bossAttack, i, bossPhase), position.y - val2.y))
					{
						return true;
					}
				}
			}
			return false;
		}
		return FinalBossRules.Hit(bossAttack, val.x, val.z, position.y - BossSurface(position).y, bossPhase);
	}

	private void FaceBossArrival(PlayerCharacter player)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0041: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)player).transform.position - bossClearing;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			val = -finalWalk.forward;
		}
		Vector3 val2 = finalWalk.InverseTransformDirection(val);
		bossFacingRadians = Mathf.Repeat(Mathf.Atan2(val2.x, val2.z), (float)Math.PI * 2f);
		bossFacing = Quaternion.Euler(0f, bossFacingRadians * 57.29578f, 0f);
	}

	private bool FindNearbyAttackGround(Vector3 target, int attack, out Vector3 floor)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		if (FindAttackGround(target, attack, out floor))
		{
			return true;
		}
		for (int i = 1; i <= 3; i++)
		{
			for (int j = 0; j < 8; j++)
			{
				float num = (float)j * (float)Math.PI / 4f;
				Vector3 target2 = target + (finalWalk.right * Mathf.Cos(num) + finalWalk.forward * Mathf.Sin(num)) * (float)(i * 2);
				if (FindAttackGround(target2, attack, out floor))
				{
					return true;
				}
			}
		}
		return false;
	}

	private void BuildBossBarrier(Material material)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_0097: 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_00d5: 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_010f: 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_0032: 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_0157: 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)
		Vector3 val = bossClearing - wallOrigin;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			val = -finalWalk.forward;
		}
		((Vector3)(ref val)).Normalize();
		bossBarrier = new GameObject("Glitched progression seal");
		bossBarrier.transform.SetParent(bossRoot.transform, false);
		bossBarrier.transform.SetPositionAndRotation(bossClearing + val * 48f, Quaternion.LookRotation(val, Vector3.up));
		BoxCollider obj = bossBarrier.AddComponent<BoxCollider>();
		obj.center = new Vector3(0f, 24f, 0f);
		obj.size = new Vector3(320f, 96f, 3f);
		BossPart(bossBarrier, "Sealed route", (PrimitiveType)3, new Vector3(0f, 24f, 0f), new Vector3(320f, 96f, 2f), material);
		Material mat = BossMaterial(new Color(0.15f, 0.85f, 0.8f));
		for (int i = -8; i <= 8; i++)
		{
			BossPart(bossBarrier, "Fractured seal seam", (PrimitiveType)3, new Vector3((float)(i * 20), 24f, -1.1f), new Vector3(0.15f, 96f, 0.1f), mat);
		}
		bossBarrier.SetActive(FinalBossRules.BarrierActive(bossState));
	}

	private Vector3 BossBellDesired(int index)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		return bossClearing + finalWalk.right * FinalBossRules.BellX(index) + finalWalk.forward * FinalBossRules.BellZ(index);
	}

	private bool NearBossArena(PlayerCharacter p)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		if (!bossClearingReady)
		{
			return false;
		}
		Vector3 val = ((Component)p).transform.position - (bossClearing + Vector3.up * 300f);
		return FinalBossRules.NearArena(val.x, val.y, val.z);
	}

	private bool TryResolveArenaCollisionLayer()
	{
		//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_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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: 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)
		if (Time.unscaledTime < arenaLayerRetry)
		{
			return false;
		}
		arenaLayerRetry = Time.unscaledTime + 1f;
		PlayerCharacter val = LocalBossPlayer();
		if ((Object)(object)val == (Object)null || val.ground == null)
		{
			return false;
		}
		Vector3 val2 = bossClearing + Vector3.up * 312f;
		float num = float.MaxValue;
		int num2 = -1;
		foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(val2, Vector3.down, 28f, -1, (QueryTriggerInteraction)1))
		{
			RaycastHit current = item;
			if (!((Object)(object)((RaycastHit)(ref current)).collider == (Object)null) && !((Object)(object)((RaycastHit)(ref current)).collider.attachedRigidbody != (Object)null) && !(((RaycastHit)(ref current)).normal.y < 0.7f) && !(((RaycastHit)(ref current)).distance >= num))
			{
				num2 = ((Component)((RaycastHit)(ref current)).collider).gameObject.layer;
				num = ((RaycastHit)(ref current)).distance;
			}
		}
		if (num2 < 0 && (Object)(object)val.ground.groundCollider != (Object)null)
		{
			num2 = ((Component)val.ground.groundCollider).gameObject.layer;
		}
		if (num2 < 0)
		{
			bossNotice = "Waiting for surface terrain to load...";
			return false;
		}
		arenaCollisionLayer = num2;
		ManualLogSource logSource = Plugin.LogSource;
		string[] obj = new string[5]
		{
			"Arena terrain layer=",
			num2.ToString(),
			", native ground mask=",
			null,
			null
		};
		LayerMask layerMask = val.ground.layerMask;
		obj[3] = ((LayerMask)(ref layerMask)).value.ToString();
		obj[4] = "; per-arena contact overrides enabled.";
		logSource.LogInfo((object)string.Concat(obj));
		return true;
	}

	private int ArenaPlayerContactLayers()
	{
		int num = 0;
		PlayerCharacter val = LocalBossPlayer();
		if ((Object)(object)val == (Object)null)
		{
			return num;
		}
		foreach (Collider componentsInChild in ((Component)val).GetComponentsInChildren<Collider>(true))
		{
			if ((Object)(object)componentsInChild.attachedRigidbody == (Object)(object)val.rb && !componentsInChild.isTrigger)
			{
				num |= 1 << ((Component)componentsInChild).gameObject.layer;
			}
		}
		return num;
	}

	private void ConfigureArenaGround(PlayerCharacter player)
	{
		//IL_003a: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)arenaGroundPlayer != (Object)null) && !((Object)(object)player == (Object)null) && player.ground != null)
		{
			arenaGroundPlayer = player;
			int num = 1 << arenaCollisionLayer;
			LayerMask layerMask = player.ground.layerMask;
			addedArenaGroundBit = (((((LayerMask)(ref layerMask)).value & num) == 0) ? num : 0);
			PlayerGround ground = player.ground;
			layerMask = player.ground.layerMask;
			ground.layerMask = LayerMask.op_Implicit(((LayerMask)(ref layerMask)).value | num);
		}
	}

	private void RestoreArenaGround()
	{
		//IL_0039: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)arenaGroundPlayer != (Object)null && arenaGroundPlayer.ground != null && addedArenaGroundBit != 0)
		{
			PlayerGround ground = arenaGroundPlayer.ground;
			LayerMask layerMask = arenaGroundPlayer.ground.layerMask;
			ground.layerMask = LayerMask.op_Implicit(((LayerMask)(ref layerMask)).value & ~addedArenaGroundBit);
		}
		arenaGroundPlayer = null;
		addedArenaGroundBit = 0;
		arenaLayerRetry = 0f;
	}

	private bool BelowArenaFloor(PlayerCharacter player)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)customArenaRoot != (Object)null && bossState > 0 && (Object)(object)player != (Object)null)
		{
			return ((Component)player).transform.position.y < bossClearing.y - 0.25f;
		}
		return false;
	}

	private void RecoverArenaFloor()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		if (!arenaArrived || arenaReturned || (Object)(object)customArenaRoot == (Object)null || BossLocalDead)
		{
			return;
		}
		PlayerCharacter val = LocalBossPlayer();
		if ((Object)(object)val == (Object)null || (Object)(object)val.rb == (Object)null || !BelowArenaFloor(val))
		{
			return;
		}
		Vector3 val2 = customArenaRoot.transform.InverseTransformPoint(((Component)val).transform.position);
		val2.x = Mathf.Clamp(val2.x, -38f, 38f);
		val2.z = Mathf.Clamp(val2.z, -48f, 48f);
		val2.y = 1f;
		HostPhysicsSnapshot hostPhysicsSnapshot = new HostPhysicsSnapshot(val);
		Vector3 origin = customArenaRoot.transform.TransformPoint(val2);
		if (hostPhysicsSnapshot.TryUsePosition(origin) || hostPhysicsSnapshot.TryUsePosition(bossClearing - finalWalk.forward * 22f + Vector3.up))
		{
			hostPhysicsSnapshot.Restore();
			if (!val.rb.isKinematic)
			{
				val.rb.linearVelocity = Vector3.zero;
			}
			if (SharedDriver)
			{
				bossGrace[BossId(val)] = Time.unscaledTime + 8f;
			}
			if (Time.unscaledTime >= floorRecoveryLogAt)
			{
				floorRecoveryLogAt = Time.unscaledTime + 2f;
				Plugin.LogSource.LogWarning((object)("Recovered local player below arena floor; collisions=" + val.rb.detectCollisions + ", kinematic=" + val.rb.isKinematic));
			}
		}
	}

	private void BuildAttackAnimation()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Expected O, but got Unknown
		//IL_0120: 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)
		Material val = BossMaterial(new Color(0.025f, 0.009f, 0.035f));
		Material mat = BossGlow(new Color(0.8f, 0.04f, 0.16f));
		for (int i = 0; i < 2; i++)
		{
			attackUpper[i] = BossPart(bossRoot, "Articulated upper arm", (PrimitiveType)1, Vector3.zero, Vector3.one, val).transform;
			attackFore[i] = BossPart(bossRoot, "Articulated forearm", (PrimitiveType)1, Vector3.zero, Vector3.one, val).transform;
			attackHands[i] = BossPart(bossRoot, "Impact fist", (PrimitiveType)0, Vector3.zero, new Vector3(3f, 2f, 3f), val).transform;
		}
		BuildBossFingers(val);
		waveRoot = new GameObject("Expanding shockwave");
		waveRoot.transform.SetParent(bossRoot.transform, false);
		for (int j = 0; j < waveSegments.Length; j++)
		{
			waveSegments[j] = BossPart(waveRoot, "Wave arc", (PrimitiveType)3, Vector3.zero, Vector3.one, mat).transform;
		}
	}

	private void ArmSegment(Transform segment, Vector3 a, Vector3 b, float width)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_001e: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		segment.position = (a + b) * 0.5f;
		Vector3 up = Vector3.up;
		Vector3 val = b - a;
		segment.rotation = Quaternion.FromToRotation(up, ((Vector3)(ref val)).normalized);
		segment.localScale = new Vector3(width, Vector3.Distance(a, b) * 0.5f, width);
	}

	private void PoseBossCombatBody()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)bossBody == (Object)null))
		{
			float num = FinalBossRules.Smooth(bossPhase / 1.25f);
			float num2 = Mathf.Pow(Mathf.Clamp01((bossPhase - 1.25f) / 0.55f), 3f);
			float num3 = 1f - FinalBossRules.Smooth((bossPhase - FinalBossRules.AttackEnd(bossAttack)) / 1.1f);
			bossBody.transform.localRotation = bossFacing * Quaternion.Euler(((bossAttack == 1) ? 0f : (-8f * num + 14f * num2)) * num3, (bossAttack == 1) ? ((-18f * num + 36f * num2) * num3) : 0f, 0f);
			bossBody.transform.localPosition = bossBodyRest - Vector3.up * ((float)((bossAttack != 2) ? 1 : 2) * num2 * num3);
		}
	}

	private void AnimateBossAttack(Vector3 ground, bool retreating)
	{
		//IL_00e2: 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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: 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_011e: 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_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)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: 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_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)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0584: Unknown result type (might be due to invalid IL or missing references)
		//IL_059e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0606: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0481: Unknown result type (might be due to invalid IL or missing references)
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_0494: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04da: Unknown result type (might be due to invalid IL or missing references)
		//IL_04de: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0411: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0422: Unknown result type (might be due to invalid IL or missing references)
		//IL_0428: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)waveRoot == (Object)null)
		{
			BuildAttackAnimation();
		}
		float num = bossPhase;
		float num2 = FinalBossRules.Smooth(num / 1.25f);
		float num3 = Mathf.Pow(Mathf.Clamp01((num - 1.25f) / 0.55f), 3f);
		float num4 = FinalBossRules.Smooth((num - FinalBossRules.AttackEnd(bossAttack)) / 1.1f);
		if (!retreating)
		{
			PoseBossCombatBody();
		}
		for (int i = 0; i < 2; i++)
		{
			((Component)attackUpper[i]).gameObject.SetActive(!retreating);
			((Component)attackFore[i]).gameObject.SetActive(!retreating);
			((Component)attackHands[i]).gameObject.SetActive(!retreating);
			if (!retreating)
			{
				float num5 = ((i != 0) ? 1 : (-1));
				Vector3 val = bossBody.transform.TransformPoint(new Vector3(num5 * 20f, 37.5f, 0f));
				Vector3 val2 = bossBody.transform.TransformPoint(new Vector3(num5 * 26f, -6f, 0f));
				Vector3 val3 = ground + finalWalk.right * num5 * 1.2f + Vector3.up;
				Vector3 val4 = val3 + Vector3.up * 22f - finalWalk.forward * 4f;
				if (bossAttack == 1)
				{
					val3 = BossSurface(ground + finalWalk.forward * FinalBossRules.SweepZ(num)) + Vector3.up;
					val4 = ground - finalWalk.forward * 12f + finalWalk.right * num5 * 7f + Vector3.up * 9f;
				}
				else if (bossAttack == 2)
				{
					val4 = ground + finalWalk.right * num5 * 9f + Vector3.up * 12f;
					val3 = ground + finalWalk.right * num5 * 1.2f + Vector3.up;
				}
				if (bossAttack == 3)
				{
					val4 = val + Vector3.up * 20f;
					val3 = val + finalWalk.forward * 8f;
				}
				if (bossAttack == 4)
				{
					val4 = ground + finalWalk.right * num5 * 12f + Vector3.up * 12f;
					val3 = ground + finalWalk.right * FinalBossRules.ShardRow(i) + Vector3.up * 4f;
				}
				if (bossAttack == 5)
				{
					val4 = val + Vector3.up * 10f + finalWalk.forward * 8f;
					val3 = val + Vector3.down * 12f + finalWalk.forward * 12f;
				}
				if (bossAttack >= 6)
				{
					val4 = val + Vector3.up * 24f;
					val3 = val + finalWalk.right * num5 * 18f + Vector3.up * 16f;
				}
				Vector3 val5 = Vector3.Lerp(Vector3.Lerp(val2, val4, num2), val3, num3);
				if (bossAttack == 1 && i == 0)
				{
					val5 = Vector3.Lerp(val2, val2 + Vector3.up * 8f, num2);
				}
				val5 = Vector3.Lerp(val5, val2, num4);
				Vector3 val6 = Vector3.Lerp(val, val5, 0.48f) + finalWalk.right * num5 * (5f + 5f * num2) + Vector3.up * 3f;
				ArmSegment(attackUpper[i], val, val6, 3f);
				ArmSegment(attackFore[i], val6, val5, 2.5f);
				attackHands[i].position = val5;
				Transform obj = attackHands[i];
				Vector3 val7 = val5 - val;
				obj.rotation = Quaternion.LookRotation(((Vector3)(ref val7)).normalized, finalWalk.forward);
				AnimateBossFingers(i, num2, num3, num4);
			}
		}
		bool flag = !retreating && bossGroundReady && bossAttack == 2 && num >= 1.8f && num < 2.5f;
		waveRoot.SetActive(flag);
		if (flag)
		{
			float num6 = FinalBossRules.WaveRadius(num);
			for (int j = 0; j < waveSegments.Length; j++)
			{
				float num7 = (float)j * (float)Math.PI * 2f / (float)waveSegments.Length;
				Transform obj2 = waveSegments[j];
				obj2.position = BossSurface(ground + new Vector3(Mathf.Cos(num7) * num6, 0f, Mathf.Sin(num7) * num6)) + Vector3.up * 0.3f;
				obj2.rotation = Quaternion.Euler(0f, (0f - num7) * 57.29578f, 0f);
				obj2.localScale = new Vector3(0.9f, 0.55f, (float)Math.PI * 2f * num6 / (float)waveSegments.Length * 1.1f);
			}
		}
	}

	private void BuildAttackArt()
	{
		//IL_0020: 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_0060: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)crystalDark != (Object)null))
		{
			crystalDark = BossMaterial(new Color(0.035f, 0.018f, 0.095f));
			crystalLight = BossMaterial(new Color(0.16f, 0.32f, 0.45f));
			crystalCore = BossGlow(new Color(0.32f, 1f, 0.88f));
			if (crystalDark.HasProperty("_Smoothness"))
			{
				crystalDark.SetFloat("_Smoothness", 0.82f);
			}
			if (crystalLight.HasProperty("_Metallic"))
			{
				crystalLight.SetFloat("_Metallic", 0.65f);
			}
			warningFill = BossTransparent(new Color(1f, 0.08f, 0.24f, 0.13f), 1.4f);
			warningEdge = BossTransparent(new Color(1f, 0.35f, 0.5f, 0.78f), 3f);
			crystalMesh = MakeCrystalMesh();
			warningDisc = MakeWarningMesh(round: true, hollow: false, edge: false);
			warningRing = MakeWarningMesh(round: true, hollow: true, edge: false);
			warningSquare = MakeWarningMesh(round: false, hollow: false, edge: false);
		}
	}

	private Material BossTransparent(Color color, float emission)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		Material val = BossMaterial(color);
		if (!val.HasProperty("_Surface"))
		{
			Shader val2 = Shader.Find("Universal Render Pipeline/Unlit");
			if ((Object)(object)val2 != (Object)null && val2.isSupported)
			{
				val.shader = val2;
			}
		}
		string[] array = new string[2] { "_Color", "_BaseColor" };
		foreach (string text in array)
		{
			if (val.HasProperty(text))
			{
				val.SetColor(text, color);
			}
		}
		if (val.HasProperty("_Surface"))
		{
			val.SetFloat("_Surface", 1f);
		}
		if (val.HasProperty("_Blend"))
		{
			val.SetFloat("_Blend", 0f);
		}
		if (val.HasProperty("_SrcBlend"))
		{
			val.SetInt("_SrcBlend", 5);
		}
		if (val.HasProperty("_DstBlend"))
		{
			val.SetInt("_DstBlend", 10);
		}
		if (val.HasProperty("_ZWrite"))
		{
			val.SetInt("_ZWrite", 0);
		}
		if (val.HasProperty("_ZTest"))
		{
			val.SetInt("_ZTest", 4);
		}
		if (val.HasProperty("_Cull"))
		{
			val.SetInt("_Cull", 0);
		}
		if (val.HasProperty("_EmissionColor"))
		{
			val.SetColor("_EmissionColor", new Color(color.r * emission, color.g * emission, color.b * emission));
			val.EnableKeyword("_EMISSION");
		}
		val.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
		val.DisableKeyword("_ALPHATEST_ON");
		val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
		val.SetOverrideTag("RenderType", "Transparent");
		val.renderQueue = 3000;
		return val;
	}

	private Mesh MakeCrystalMesh()
	{
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown r