Decompiled source of Garden of Sacrifice v1.0.0

plugins/GardenOfSacrifice/GardenOfSacrifice.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Treebot.TreebotFlower;
using EntityStates.Treebot.Weapon;
using HarmonyLib;
using RoR2;
using RoR2.Projectile;
using RoR2.UI;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.SceneManagement;

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

internal static class CastTimeline
{
	internal static bool Reached(float distanceSquared, float radius)
	{
		if (radius > 0f)
		{
			return distanceSquared <= radius * radius;
		}
		return false;
	}

	internal static float Expansion(float age, float seconds)
	{
		float num = Math.Max(0f, Math.Min(1f, age / Math.Max(0.01f, seconds)));
		return num * num * (3f - 2f * num);
	}
}
internal static class ChargeRules
{
	internal static float Add(float charge, float dealt, float baseDamage, float multiplier)
	{
		if (float.IsNaN(dealt) || float.IsInfinity(dealt) || dealt <= 0f || baseDamage <= 0f || multiplier <= 0f)
		{
			return charge;
		}
		float num = charge + dealt / (baseDamage * multiplier);
		if (!(num >= 0.99999f))
		{
			return num;
		}
		return 1f;
	}
}
internal sealed class CrystalBarrier : MonoBehaviour
{
	private const int Columns = 36;

	private const int Rows = 18;

	private const int Shards = 72;

	private Mesh facets;

	private Mesh cracks;

	private Material exterior;

	private Material interior;

	private Material edgeMaterial;

	private MeshRenderer outsideRenderer;

	private MeshRenderer insideRenderer;

	private MeshRenderer edgeRenderer;

	private Vector3[] rest;

	private Vector3[] vertices;

	private Vector3[] edgeVertices;

	private Vector3[] normals;

	private Color[] colors;

	private Color[] innerColors;

	private Color[] edgeColors;

	private Mesh insideMesh;

	private float[] wave;

	private float[] seed;

	private float radius;

	private bool cyan;

	private bool ice;

	private bool violet;

	private bool gold;

	private bool midnight;

	private float iceCollapse;

	private float iceStress;

	internal static CrystalBarrier Create(Transform parent, float radius, bool cyan = false, bool ice = false, bool violet = false, bool gold = false, bool midnight = false)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		GameObject val = new GameObject("Black crystalline formation");
		val.transform.SetParent(parent, false);
		CrystalBarrier crystalBarrier = val.AddComponent<CrystalBarrier>();
		crystalBarrier.radius = radius;
		crystalBarrier.midnight = midnight;
		crystalBarrier.gold = gold;
		crystalBarrier.violet = violet;
		crystalBarrier.cyan = cyan;
		crystalBarrier.ice = ice;
		try
		{
			crystalBarrier.Build();
			return crystalBarrier;
		}
		catch
		{
			Object.Destroy((Object)(object)val);
			throw;
		}
	}

	private Mesh MakeMesh(string name, Material material, out MeshRenderer renderer)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(((Component)this).transform, false);
		Mesh val2 = new Mesh();
		((Object)val2).name = name;
		Mesh val3 = val2;
		val3.MarkDynamic();
		val.AddComponent<MeshFilter>().sharedMesh = val3;
		renderer = val.AddComponent<MeshRenderer>();
		((Renderer)renderer).sharedMaterial = material;
		((Renderer)renderer).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)renderer).receiveShadows = false;
		return val3;
	}

	private Vector3 Point(int x, int y)
	{
		//IL_0049: 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)
		float num = MathF.PI * (float)y / 18f;
		float num2 = MathF.PI * 2f * ((float)x + (float)(y % 2) * 0.32f) / 36f;
		return new Vector3(Mathf.Sin(num) * Mathf.Cos(num2), Mathf.Cos(num), Mathf.Sin(num) * Mathf.Sin(num2)) * radius;
	}

	private void Face(List<Vector3> list, Vector3 a, Vector3 b, Vector3 c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.Cross(b - a, c - a);
		if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
		{
			if (Vector3.Dot(Vector3.Cross(b - a, c - a), a + b + c) < 0f)
			{
				Vector3 val2 = b;
				b = c;
				c = val2;
			}
			list.Add(a);
			list.Add(b);
			list.Add(c);
		}
	}

	private void Build()
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_00fc: 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_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: 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_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_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: 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)
		//IL_0438: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		exterior = DomainVisual.CreateGlowMaterial();
		interior = DomainVisual.CreateGlowMaterial();
		edgeMaterial = DomainVisual.CreateGlowMaterial();
		((Object)exterior).name = "Obsidian domain exterior";
		((Object)interior).name = "Readable domain interior";
		Material[] array = (Material[])(object)new Material[2] { exterior, interior };
		foreach (Material val in array)
		{
			val.SetInt("_DstBlend", 10);
			val.renderQueue = 3110;
		}
		exterior.SetInt("_Cull", 2);
		interior.SetInt("_Cull", 1);
		edgeMaterial.renderQueue = 3111;
		List<Vector3> list = new List<Vector3>();
		for (int j = 0; j < 18; j++)
		{
			for (int k = 0; k < 36; k++)
			{
				Face(list, Point(k, j), Point(k, j + 1), Point(k + 1, j));
				Face(list, Point(k + 1, j), Point(k, j + 1), Point(k + 1, j + 1));
			}
		}
		rest = list.ToArray();
		vertices = (Vector3[])(object)new Vector3[rest.Length];
		colors = (Color[])(object)new Color[rest.Length];
		innerColors = (Color[])(object)new Color[rest.Length];
		int num = rest.Length / 3;
		normals = (Vector3[])(object)new Vector3[num];
		wave = new float[num];
		seed = new float[num];
		edgeVertices = (Vector3[])(object)new Vector3[num * 12 + 216];
		edgeColors = (Color[])(object)new Color[edgeVertices.Length];
		int[] array2 = new int[rest.Length];
		int[] array3 = new int[num * 18 + 216];
		for (int l = 0; l < rest.Length; l++)
		{
			array2[l] = l;
		}
		for (int m = 0; m < num; m++)
		{
			ref Vector3 reference = ref normals[m];
			Vector3 val2 = (rest[m * 3] + rest[m * 3 + 1] + rest[m * 3 + 2]) / 3f;
			reference = ((Vector3)(ref val2)).normalized;
			seed[m] = Mathf.Repeat((float)m * 0.618034f, 1f);
			wave[m] = Mathf.Clamp01((1f - normals[m].y) * 0.43f + seed[m] * 0.12f);
			for (int n = 0; n < 3; n++)
			{
				int num2 = m * 12 + n * 4;
				int num3 = m * 18 + n * 6;
				array3[num3] = num2;
				array3[num3 + 1] = num2 + 2;
				array3[num3 + 2] = num2 + 1;
				array3[num3 + 3] = num2 + 1;
				array3[num3 + 4] = num2 + 2;
				array3[num3 + 5] = num2 + 3;
			}
		}
		for (int num4 = 0; num4 < 216; num4++)
		{
			array3[num * 18 + num4] = num * 12 + num4;
		}
		facets = MakeMesh("Black exterior facets", exterior, out outsideRenderer);
		insideMesh = MakeMesh("Translucent interior facets", interior, out insideRenderer);
		cracks = MakeMesh("Crimson fracture network", edgeMaterial, out edgeRenderer);
		Mesh[] array4 = (Mesh[])(object)new Mesh[2] { facets, insideMesh };
		foreach (Mesh val3 in array4)
		{
			val3.vertices = rest;
			val3.uv = (Vector2[])(object)new Vector2[rest.Length];
			val3.triangles = array2;
			val3.bounds = new Bounds(Vector3.zero, Vector3.one * radius * 2.15f);
		}
		cracks.vertices = edgeVertices;
		cracks.uv = (Vector2[])(object)new Vector2[edgeVertices.Length];
		cracks.triangles = array3;
		cracks.bounds = facets.bounds;
	}

	internal void DrawIce(float age, float opening, float fade, float collapse, float stress = 0f)
	{
		iceStress = stress;
		iceCollapse = collapse;
		Draw(age, opening, fade);
	}

	internal void ExteriorForCamera(bool visible)
	{
		if (Object.op_Implicit((Object)(object)outsideRenderer))
		{
			((Renderer)outsideRenderer).enabled = visible && Object.op_Implicit((Object)(object)insideRenderer) && ((Renderer)insideRenderer).enabled;
		}
	}

	internal void Draw(float age, float opening, float fade)
	{
		//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_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_017f: 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_0272: 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_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_079d: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0808: Unknown result type (might be due to invalid IL or missing references)
		//IL_080d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0814: Unknown result type (might be due to invalid IL or missing references)
		//IL_081b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0820: Unknown result type (might be due to invalid IL or missing references)
		//IL_0825: Unknown result type (might be due to invalid IL or missing references)
		//IL_0860: Unknown result type (might be due to invalid IL or missing references)
		//IL_0862: Unknown result type (might be due to invalid IL or missing references)
		//IL_0869: Unknown result type (might be due to invalid IL or missing references)
		//IL_0873: Unknown result type (might be due to invalid IL or missing references)
		//IL_0878: Unknown result type (might be due to invalid IL or missing references)
		//IL_087d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0891: Unknown result type (might be due to invalid IL or missing references)
		//IL_0893: Unknown result type (might be due to invalid IL or missing references)
		//IL_0897: Unknown result type (might be due to invalid IL or missing references)
		//IL_089c: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_08bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_09cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_09ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_09cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_09db: Unknown result type (might be due to invalid IL or missing references)
		//IL_09e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_09e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0403: Unknown result type (might be due to invalid IL or missing references)
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_0419: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_0438: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0644: Unknown result type (might be due to invalid IL or missing references)
		//IL_064e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0653: Unknown result type (might be due to invalid IL or missing references)
		//IL_066b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0675: Unknown result type (might be due to invalid IL or missing references)
		//IL_067a: Unknown result type (might be due to invalid IL or missing references)
		//IL_067c: Unknown result type (might be due to invalid IL or missing references)
		//IL_067e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0680: Unknown result type (might be due to invalid IL or missing references)
		//IL_0682: Unknown result type (might be due to invalid IL or missing references)
		//IL_0687: Unknown result type (might be due to invalid IL or missing references)
		//IL_068c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0690: Unknown result type (might be due to invalid IL or missing references)
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0707: Unknown result type (might be due to invalid IL or missing references)
		//IL_0709: Unknown result type (might be due to invalid IL or missing references)
		//IL_070b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0710: Unknown result type (might be due to invalid IL or missing references)
		//IL_0724: Unknown result type (might be due to invalid IL or missing references)
		//IL_0726: Unknown result type (might be due to invalid IL or missing references)
		//IL_0728: Unknown result type (might be due to invalid IL or missing references)
		//IL_072d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0747: Unknown result type (might be due to invalid IL or missing references)
		//IL_0749: Unknown result type (might be due to invalid IL or missing references)
		float num = ((ice || violet || gold || midnight) ? iceCollapse : FormationTimeline.Reveal(age, opening));
		bool flag = num < 1f && fade > 0.001f;
		MeshRenderer obj = outsideRenderer;
		MeshRenderer obj2 = insideRenderer;
		bool flag2 = (((Renderer)edgeRenderer).enabled = flag);
		bool enabled = (((Renderer)obj2).enabled = flag2);
		((Renderer)obj).enabled = enabled;
		if (!flag)
		{
			return;
		}
		float num2 = FormationTimeline.Crystal(age, opening);
		float num3 = Plugin.Clamp(Plugin.CrystalIntensity.Value, 0f, 1.5f);
		Color val3 = default(Color);
		Color val5 = default(Color);
		for (int i = 0; i < normals.Length; i++)
		{
			float num4 = CastTimeline.Expansion(num2 * 1.2f - wave[i], 0.2f);
			float num5 = CastTimeline.Expansion(num * 1.22f - seed[i] * 0.2f, 1f);
			float num6 = Mathf.Pow(Mathf.Max(0f, Mathf.Cos(wave[i] * 16f - age * 2.6f)), 12f);
			float num7 = (1f - num5) * fade;
			Vector3 val = normals[i];
			Vector3 val2 = (rest[i * 3] + rest[i * 3 + 1] + rest[i * 3 + 2]) / 3f;
			float num8 = num4 * seed[i] * radius * 0.002f + num5 * num5 * radius * 0.035f;
			float num9 = 1f - num5 * 0.85f;
			float num10 = 0.008f + seed[i] * 0.018f * num4;
			((Color)(ref val3))..ctor(num10 * 0.65f + num6 * 0.018f, num10 * 0.2f, num10 + num6 * 0.025f, Plugin.Clamp(Plugin.BlackOpacity.Value, 0f, 1f) * num7);
			if (cyan)
			{
				((Color)(ref val3))..ctor(num10 * 0.12f, num10 * 0.45f, num10 + num6 * 0.025f, val3.a);
			}
			if (ice)
			{
				val3 = Color.Lerp(new Color(0.012f, 0.024f, 0.045f, 0.85f), new Color(0.72f, 0.88f, 1f, 0.17f), num4);
				val3.a *= num7;
			}
			if (violet)
			{
				((Color)(ref val3))..ctor(0.012f + num6 * 0.015f, 0.003f, 0.032f + num6 * 0.04f, num7 * 0.92f);
			}
			if (gold)
			{
				((Color)(ref val3))..ctor(0.018f, 0.009f, 0.012f, num7 * 0.97f);
			}
			if (midnight)
			{
				((Color)(ref val3))..ctor(0.018f, 0.028f, 0.095f, num7 * 0.98f);
			}
			Color val4 = val3;
			val4.a = Plugin.Clamp(Plugin.InnerOpacity.Value, 0f, 0.45f) * num7;
			if (midnight)
			{
				val4.a = num7 * 0.025f;
			}
			if (gold)
			{
				val4.a = num7 * 0.03f;
			}
			if (violet)
			{
				val4.a = num7 * 0.025f * Mathf.Max(1f - CastTimeline.Expansion(age - opening * 0.35f, opening * 0.5f), CastTimeline.Expansion(num, 0.45f));
			}
			if (ice)
			{
				val4.a = Mathf.Lerp(0.14f, 0.045f, num4) * num7;
			}
			for (int j = 0; j < 3; j++)
			{
				int num11 = i * 3 + j;
				ref Vector3 reference = ref vertices[num11];
				reference = val2 + (rest[num11] - val2) * num9 + val * num8;
				colors[num11] = val3;
				innerColors[num11] = val4;
			}
			float num12 = num4 * (0.22f + num2 * 0.4f + num * 2f + num6 * 0.16f);
			((Color)(ref val5))..ctor(2.8f, 0.04f + num * 0.18f, 0.2f + num * 0.15f, num12 * num7 * num3);
			if (cyan)
			{
				((Color)(ref val5))..ctor(0.08f, 1.7f + num * 0.3f, 2.8f, val5.a);
			}
			if (ice)
			{
				((Color)(ref val5))..ctor(0.72f, 1.05f, 1.3f, num4 * num7 * (0.035f + num * 0.6f + iceStress * 0.85f + ((age < opening) ? 0.16f : 0f)));
			}
			if (violet)
			{
				((Color)(ref val5))..ctor(0.7f, 0.13f, 1.35f, num7 * num4 * (0.018f + num6 * 0.12f + num * 0.4f + ((age < opening) ? 0.16f : 0f)) * Mathf.Max(1f - CastTimeline.Expansion(age - opening * 0.35f, opening * 0.5f), CastTimeline.Expansion(num, 0.45f)));
			}
			if (gold)
			{
				((Color)(ref val5))..ctor(1.5f, 0.72f, 0.08f, num7 * num4 * (0.13f + num6 * 0.1f + num * 0.5f));
			}
			if (midnight)
			{
				((Color)(ref val5))..ctor(0.48f, 0.66f, 1f, num7 * num4 * (0.035f + num6 * 0.025f + num * 0.12f));
			}
			for (int k = 0; k < 3; k++)
			{
				Vector3 val6 = vertices[i * 3 + k] * 1.0006f;
				Vector3 val7 = vertices[i * 3 + (k + 1) % 3] * 1.0006f;
				Vector3 val8 = Vector3.Cross(val, val7 - val6);
				Vector3 val9 = ((Vector3)(ref val8)).normalized * radius * (0.0004f + num * 0.00045f);
				int num13 = i * 12 + k * 4;
				ref Vector3 reference2 = ref edgeVertices[num13];
				reference2 = val6 - val9;
				ref Vector3 reference3 = ref edgeVertices[num13 + 1];
				reference3 = val6 + val9;
				ref Vector3 reference4 = ref edgeVertices[num13 + 2];
				reference4 = val7 - val9;
				ref Vector3 reference5 = ref edgeVertices[num13 + 3];
				reference5 = val7 + val9;
				for (int l = 0; l < 4; l++)
				{
					edgeColors[num13 + l] = val5;
				}
			}
		}
		Color val14 = default(Color);
		for (int m = 0; m < 72; m++)
		{
			Vector3 val10 = normals[m * 17 % normals.Length];
			Vector3 val11 = Vector3.Cross(val10, Vector3.up);
			Vector3 val12 = ((Vector3)(ref val11)).normalized;
			if (((Vector3)(ref val12)).sqrMagnitude < 0.1f)
			{
				val12 = Vector3.right;
			}
			float num14 = Mathf.Repeat(age * 0.65f + (float)m * 0.618034f, 1f);
			Vector3 val13 = val10 * radius * (1.003f + num14 * 0.025f) + Vector3.down * num14 * num14;
			float num15 = radius * (0.001f + (float)(m % 3) * 0.0006f);
			int num16 = normals.Length * 12 + m * 3;
			ref Vector3 reference6 = ref edgeVertices[num16];
			reference6 = val13 + Vector3.up * num15 * 2f;
			ref Vector3 reference7 = ref edgeVertices[num16 + 1];
			reference7 = val13 - val12 * num15;
			ref Vector3 reference8 = ref edgeVertices[num16 + 2];
			reference8 = val13 + val12 * num15;
			((Color)(ref val14))..ctor(2f, 0.02f, 0.2f, num2 * (1f - num) * fade * Mathf.Sin(num14 * MathF.PI) * 0.6f * num3);
			if (cyan)
			{
				((Color)(ref val14))..ctor(0.06f, 1.4f, 2f, val14.a);
			}
			if (violet)
			{
				((Color)(ref val14))..ctor(0.6f, 0.08f, 1.3f, val14.a * 0.3f);
			}
			if (gold)
			{
				((Color)(ref val14))..ctor(1.5f, 0.65f, 0.06f, val14.a);
			}
			if (midnight)
			{
				((Color)(ref val14))..ctor(0.5f, 0.7f, 1f, val14.a * 0.12f);
			}
			ref Color reference9 = ref edgeColors[num16];
			ref Color reference10 = ref edgeColors[num16 + 1];
			reference9 = (reference10 = (edgeColors[num16 + 2] = val14));
		}
		facets.vertices = vertices;
		facets.colors = colors;
		insideMesh.vertices = vertices;
		insideMesh.colors = innerColors;
		cracks.vertices = edgeVertices;
		cracks.colors = edgeColors;
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)facets))
		{
			Object.Destroy((Object)(object)facets);
		}
		if (Object.op_Implicit((Object)(object)insideMesh))
		{
			Object.Destroy((Object)(object)insideMesh);
		}
		if (Object.op_Implicit((Object)(object)cracks))
		{
			Object.Destroy((Object)(object)cracks);
		}
		if (Object.op_Implicit((Object)(object)exterior))
		{
			Object.Destroy((Object)(object)exterior);
		}
		if (Object.op_Implicit((Object)(object)interior))
		{
			Object.Destroy((Object)(object)interior);
		}
		if (Object.op_Implicit((Object)(object)edgeMaterial))
		{
			Object.Destroy((Object)(object)edgeMaterial);
		}
	}
}
public sealed class DomainAtmosphere : MonoBehaviour
{
	private Transform owner;

	private PostProcessVolume volume;

	private PostProcessProfile profile;

	private Light ambient;

	private bool reported;

	private bool ice;

	private bool violet;

	private bool casino;

	private bool garden;

	private bool midnight;

	private bool tactical;

	private ColorGrading grade;

	private float baseExposure;

	internal bool CameraSupported { get; private set; }

	internal static DomainAtmosphere Create(Transform owner, float radius, bool cyan)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Expected O, but got Unknown
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Local crimson domain atmosphere");
		val.transform.SetParent(owner, false);
		val.layer = LayerIndex.postProcess.intVal;
		DomainAtmosphere domainAtmosphere = val.AddComponent<DomainAtmosphere>();
		domainAtmosphere.owner = owner;
		SphereCollider val2 = val.AddComponent<SphereCollider>();
		((Collider)val2).isTrigger = true;
		val2.radius = radius;
		domainAtmosphere.volume = val.AddComponent<PostProcessVolume>();
		domainAtmosphere.volume.isGlobal = false;
		domainAtmosphere.volume.priority = 100f;
		domainAtmosphere.volume.blendDistance = 4f;
		domainAtmosphere.volume.weight = 0f;
		domainAtmosphere.profile = ScriptableObject.CreateInstance<PostProcessProfile>();
		((Object)domainAtmosphere.profile).name = "Endless Arrow Rain local grade";
		ColorGrading val3 = (domainAtmosphere.grade = domainAtmosphere.profile.AddSettings<ColorGrading>());
		((ParameterOverride<bool>)(object)((PostProcessEffectSettings)domainAtmosphere.profile.AddSettings<RampFog>()).enabled).Override(true);
		((ParameterOverride<bool>)(object)((PostProcessEffectSettings)val3).enabled).Override(true);
		((ParameterOverride<float>)(object)val3.postExposure).Override(-0.55f * Plugin.Clamp(Plugin.ScreenDarkness.Value / 0.18f, 0f, 2f));
		domainAtmosphere.baseExposure = ((ParameterOverride<float>)(object)val3.postExposure).value;
		((ParameterOverride<float>)(object)val3.saturation).Override(-24f);
		((ParameterOverride<float>)(object)val3.contrast).Override(10f);
		((ParameterOverride<Color>)(object)val3.colorFilter).Override(new Color(1f, 0.96f, 1f));
		if (cyan)
		{
			((ParameterOverride<Color>)(object)val3.colorFilter).Override(new Color(0.5f, 0.8f, 1f));
			((ParameterOverride<float>)(object)val3.postExposure).Override(-1f);
			domainAtmosphere.baseExposure = -1f;
		}
		domainAtmosphere.volume.sharedProfile = domainAtmosphere.profile;
		GameObject val4 = new GameObject("Subtle domain red illumination");
		val4.transform.SetParent(val.transform, false);
		val4.transform.localPosition = Vector3.up * 4f;
		domainAtmosphere.ambient = val4.AddComponent<Light>();
		domainAtmosphere.ambient.type = (LightType)2;
		domainAtmosphere.ambient.color = new Color(1f, 0.015f, 0.065f);
		if (cyan)
		{
			domainAtmosphere.ambient.color = new Color(0.04f, 0.7f, 1f);
		}
		domainAtmosphere.ambient.range = radius;
		domainAtmosphere.ambient.shadows = (LightShadows)0;
		domainAtmosphere.ambient.intensity = 0f;
		return domainAtmosphere;
	}

	internal void ConfigureTactical()
	{
		//IL_0083: 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)
		tactical = true;
		RampFog setting = profile.GetSetting<RampFog>();
		((ParameterOverride<float>)(object)setting.fogIntensity).Override(0f);
		((ParameterOverride<float>)(object)setting.fogHeightIntensity).Override(0f);
		baseExposure = -0.12f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.contrast).Override(14f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(0.72f, 0.86f, 1f));
		ambient.color = new Color(0.15f, 0.55f, 1f);
	}

	internal void ConfigureMidnight()
	{
		//IL_0083: 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)
		midnight = true;
		RampFog setting = profile.GetSetting<RampFog>();
		((ParameterOverride<float>)(object)setting.fogIntensity).Override(0f);
		((ParameterOverride<float>)(object)setting.fogHeightIntensity).Override(0f);
		baseExposure = -0.1f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.contrast).Override(2f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(0.78f, 0.86f, 1f));
		ambient.color = new Color(0.48f, 0.66f, 1f);
	}

	internal void ConfigureGarden()
	{
		//IL_0083: 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)
		garden = true;
		RampFog setting = profile.GetSetting<RampFog>();
		((ParameterOverride<float>)(object)setting.fogIntensity).Override(0f);
		((ParameterOverride<float>)(object)setting.fogHeightIntensity).Override(0f);
		baseExposure = 0.12f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.contrast).Override(-4f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(1f, 0.98f, 0.87f));
		ambient.color = new Color(1f, 0.82f, 0.43f);
	}

	internal void ConfigureCasino()
	{
		//IL_0083: 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)
		casino = true;
		RampFog setting = profile.GetSetting<RampFog>();
		((ParameterOverride<float>)(object)setting.fogIntensity).Override(0f);
		((ParameterOverride<float>)(object)setting.fogHeightIntensity).Override(0f);
		baseExposure = 0.1f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.contrast).Override(4f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(1f, 0.92f, 0.85f));
		ambient.color = new Color(1f, 0.38f, 0.055f);
	}

	internal void ConfigureVoid()
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		RampFog setting = profile.GetSetting<RampFog>();
		((ParameterOverride<float>)(object)setting.fogIntensity).Override(0f);
		((ParameterOverride<float>)(object)setting.fogHeightIntensity).Override(0f);
		violet = true;
		baseExposure = -0.12f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.saturation).Override(-12f);
		((ParameterOverride<float>)(object)grade.contrast).Override(8f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(0.94f, 0.94f, 1f));
		ambient.color = new Color(0.35f, 0.12f, 0.8f);
	}

	internal void ConfigureIce()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		ice = true;
		baseExposure = 0.16f;
		((ParameterOverride<float>)(object)grade.postExposure).Override(baseExposure);
		((ParameterOverride<float>)(object)grade.saturation).Override(-48f);
		((ParameterOverride<float>)(object)grade.contrast).Override(-6f);
		((ParameterOverride<Color>)(object)grade.colorFilter).Override(new Color(0.9f, 0.96f, 1f));
		ambient.color = new Color(0.65f, 0.85f, 1f);
	}

	internal void BeforeCamera(Camera camera, float weight, bool gathering, float reveal, float pulse)
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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)
		PostProcessLayer component = ((Component)camera).GetComponent<PostProcessLayer>();
		CameraSupported = Object.op_Implicit((Object)(object)component) && ((Behaviour)component).enabled && ((LayerMask)(ref component.volumeLayer)).value != 0;
		if (CameraSupported && (((LayerMask)(ref component.volumeLayer)).value & (1 << ((Component)this).gameObject.layer)) == 0)
		{
			for (int i = 0; i < 32; i++)
			{
				if ((((LayerMask)(ref component.volumeLayer)).value & (1 << i)) != 0)
				{
					((Component)this).gameObject.layer = i;
					break;
				}
			}
		}
		float num = Mathf.Max(0.025f, ((Component)owner).transform.localScale.x);
		float num2 = Mathf.Min(1f, 8f / ((Component)this).GetComponent<SphereCollider>().radius);
		((Component)this).transform.localScale = Vector3.one * Mathf.Max(num, num2) / num;
		volume.weight = weight;
		((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure - 0.35f * (1f - reveal) + pulse * 0.12f;
		((ParameterOverride<float>)(object)grade.saturation).value = Mathf.Lerp(-32f, -24f, reveal);
		ambient.intensity = (0.08f + 0.2f * reveal + pulse * 0.22f) * weight * Plugin.Clamp(Plugin.VisualIntensity.Value, 0f, 1.5f);
		if (ice)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure + pulse * 0.12f;
			((ParameterOverride<float>)(object)grade.saturation).value = -48f;
			ambient.intensity = 0.14f * weight;
		}
		if (midnight)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure - (1f - reveal) * 0.2f;
			((ParameterOverride<float>)(object)grade.saturation).value = -12f;
			ambient.intensity = 0.3f * weight;
		}
		if (tactical)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure - (1f - reveal) * 0.15f + pulse * 0.08f;
			((ParameterOverride<float>)(object)grade.saturation).value = Mathf.Lerp(-60f, -38f, reveal);
			ambient.intensity = 0.16f * weight;
		}
		if (garden)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure + pulse * 0.1f;
			((ParameterOverride<float>)(object)grade.saturation).value = 4f;
			ambient.intensity = 0.25f * weight;
		}
		if (casino)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure - (1f - reveal) * 0.18f;
			((ParameterOverride<float>)(object)grade.saturation).value = -8f;
			ambient.intensity = 0.24f * weight;
		}
		if (violet)
		{
			((ParameterOverride<float>)(object)grade.postExposure).value = baseExposure - (1f - reveal) * 0.5f;
			((ParameterOverride<float>)(object)grade.saturation).value = Mathf.Lerp(-65f, -12f, reveal);
			ambient.intensity = 0.08f * weight;
		}
		if (!reported)
		{
			reported = true;
			Plugin.Log.LogInfo((object)("Domain atmosphere: local post-processing=" + CameraSupported + " layer=" + ((Component)this).gameObject.layer + "; no global lighting/fog writes."));
		}
	}

	private void OnDestroy()
	{
		if (!Object.op_Implicit((Object)(object)profile))
		{
			return;
		}
		foreach (PostProcessEffectSettings setting in profile.settings)
		{
			if (Object.op_Implicit((Object)(object)setting))
			{
				Object.Destroy((Object)(object)setting);
			}
		}
		Object.Destroy((Object)(object)profile);
	}
}
internal static class DomainVisual
{
	private static Material glowTemplate;

	private static bool EnsureMaterial()
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)glowTemplate))
		{
			return true;
		}
		Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
		string[] array2 = new string[4] { "Particles/Standard Unlit", "Legacy Shaders/Particles/Additive", "Particles/Additive", "Sprites/Default" };
		Shader val = null;
		string[] array3 = array2;
		foreach (string text in array3)
		{
			Shader[] array4 = array;
			foreach (Shader val2 in array4)
			{
				if (Object.op_Implicit((Object)(object)val2) && ((Object)val2).name == text && val2.isSupported)
				{
					val = val2;
					break;
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				break;
			}
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			return false;
		}
		Material val3 = new Material(val);
		((Object)val3).name = "Garden of Sacrifice Glow";
		val3.renderQueue = 3100;
		glowTemplate = val3;
		if (glowTemplate.HasProperty("_MainTex"))
		{
			glowTemplate.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
		}
		if (glowTemplate.HasProperty("_Color"))
		{
			glowTemplate.SetColor("_Color", Color.white);
		}
		if (glowTemplate.HasProperty("_TintColor"))
		{
			glowTemplate.SetColor("_TintColor", Color.white);
		}
		if (glowTemplate.HasProperty("_Mode"))
		{
			glowTemplate.SetFloat("_Mode", 4f);
		}
		if (glowTemplate.HasProperty("_ColorMode"))
		{
			glowTemplate.SetFloat("_ColorMode", 0f);
		}
		glowTemplate.SetInt("_SrcBlend", 5);
		glowTemplate.SetInt("_DstBlend", 1);
		glowTemplate.SetInt("_ZWrite", 0);
		glowTemplate.SetInt("_Cull", 0);
		glowTemplate.DisableKeyword("_ALPHATEST_ON");
		glowTemplate.DisableKeyword("_ALPHAPREMULTIPLY_ON");
		glowTemplate.DisableKeyword("_ALPHAMODULATE_ON");
		glowTemplate.DisableKeyword("SOFTPARTICLES_ON");
		glowTemplate.DisableKeyword("FADING_ON");
		glowTemplate.EnableKeyword("_ALPHABLEND_ON");
		Plugin.Log.LogInfo((object)("Domain visual shader resolved: " + ((Object)val).name + " supported=" + val.isSupported));
		return true;
	}

	internal static Material CreateGlowMaterial()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		if (!EnsureMaterial())
		{
			return null;
		}
		return new Material(glowTemplate);
	}

	internal static void Clear()
	{
		if (Object.op_Implicit((Object)(object)glowTemplate))
		{
			Object.Destroy((Object)(object)glowTemplate);
		}
		glowTemplate = null;
	}
}
internal static class FormationTimeline
{
	internal static float Crystal(float age, float opening)
	{
		return CastTimeline.Expansion(age - Math.Max(0f, opening - 1.8f), Math.Min(opening, 1.8f));
	}

	internal static float Reveal(float age, float opening)
	{
		return CastTimeline.Expansion(age - opening + 0.25f, 1f);
	}
}
internal sealed class GardenAudio : MonoBehaviour
{
	private readonly GameObject[] voices = (GameObject[])(object)new GameObject[4];

	private readonly uint[] ids = new uint[4];

	private float start;

	private float opening;

	private float duration;

	private float closing = -1f;

	private float nextWind;

	private bool formed;

	private bool genesis;

	private bool loop;

	private bool impact;

	private bool warned;

	internal static GardenAudio Create(Transform parent, float age, float opening, float collapse)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		GameObject val = new GameObject("Garden of Sacrifice local soundscape");
		val.transform.SetParent(parent, false);
		GardenAudio gardenAudio = val.AddComponent<GardenAudio>();
		gardenAudio.start = Time.time - age;
		gardenAudio.opening = opening;
		gardenAudio.duration = collapse;
		gardenAudio.formed = age >= opening;
		gardenAudio.genesis = age >= opening * 0.55f;
		for (int i = 0; i < 4; i++)
		{
			GameObject val2 = new GameObject("Botanical voice " + i);
			val2.transform.SetParent(val.transform, false);
			val2.AddComponent<AkGameObj>();
			gardenAudio.voices[i] = val2;
		}
		gardenAudio.nextWind = age + 5f;
		if (age < 0.3f)
		{
			gardenAudio.Play(0, "Play_treeBot_R_shoot");
		}
		return gardenAudio;
	}

	private void Play(int slot, string name)
	{
		if (Plugin.SoundEnabled.Value && AkSoundEngine.IsInitialized())
		{
			Stop(slot, 100);
			Gain(slot);
			ids[slot] = Util.PlaySound(name, voices[slot]);
			if (ids[slot] == 0 && !warned)
			{
				warned = true;
				Plugin.Log.LogWarning((object)("Garden of Sacrifice native audio unavailable: " + name));
			}
		}
	}

	private void Stop(int slot, int fade)
	{
		if (ids[slot] != 0)
		{
			AkSoundEngine.StopPlayingID(ids[slot], fade);
			ids[slot] = 0u;
		}
	}

	private void Gain(int slot)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		float num = ((closing < 0f) ? 1f : (1f - Mathf.Clamp01((Time.time - closing) / duration)));
		foreach (AkAudioListener listener in ((BaseListenerList)AkAudioListener.DefaultListeners).ListenerList)
		{
			if (Object.op_Implicit((Object)(object)listener) && ((Behaviour)listener).isActiveAndEnabled)
			{
				AkSoundEngine.SetGameObjectOutputBusVolume(voices[slot], ((Component)listener).gameObject, Plugin.Clamp(Plugin.SoundVolume.Value, 0f, 1f) * slot switch
				{
					3 => 0.08f, 
					1 => 0.07f, 
					_ => 0.4f, 
				} * num);
			}
		}
	}

	internal void Collapse(float elapsed)
	{
		if (!(closing >= 0f))
		{
			closing = Time.time - elapsed;
			impact = elapsed > duration * 0.42f + 0.25f;
			Stop(1, 120);
			Stop(2, 90);
			if (elapsed < 0.2f)
			{
				Play(0, "Play_treeBot_R_shoot");
			}
		}
	}

	private void Update()
	{
		if (!Plugin.SoundEnabled.Value)
		{
			for (int i = 0; i < 4; i++)
			{
				Stop(i, 0);
			}
			loop = false;
		}
		else
		{
			if (Time.timeScale <= 0f)
			{
				return;
			}
			float num = Time.time - start;
			if (closing < 0f)
			{
				if (!loop)
				{
					loop = true;
					Play(1, "Play_env_desert_wind_gust");
				}
				if (!genesis && num >= opening * 0.55f)
				{
					genesis = true;
					Play(2, "Play_treeBot_R_impact");
				}
				if (!formed && num >= opening)
				{
					formed = true;
					Play(0, "Play_treeBot_m1_hit_heal");
					Stop(2, 300);
				}
				if (num >= nextWind)
				{
					nextWind = num + 7f;
					Play(3, "Play_env_desert_wind_gust");
				}
			}
			else if (!impact && Time.time - closing >= duration * 0.42f)
			{
				impact = true;
				Play(0, "Play_treeBot_m1_hit_heal");
				Play(2, "Play_treeBot_R_impact");
			}
			for (int j = 0; j < 4; j++)
			{
				Gain(j);
			}
		}
	}

	private void OnDisable()
	{
		for (int i = 0; i < 4; i++)
		{
			Stop(i, 0);
		}
	}
}
internal static class GardenCombat
{
	[HarmonyPatch]
	private static class AbilityCosts
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(AimMortar2), "OnProjectileFiredLocal", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(AimFlower), "OnProjectileFiredLocal", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(FirePlantSonicBoom), "OnEnter", (Type[])null, (Type[])null);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> input)
		{
			MethodInfo original = AccessTools.Method(typeof(HealthComponent), "TakeDamage", new Type[1] { typeof(DamageInfo) }, (Type[])null);
			int replaced = 0;
			foreach (CodeInstruction op in input)
			{
				if (CodeInstructionExtensions.Calls(op, original))
				{
					op.opcode = OpCodes.Call;
					op.operand = AccessTools.Method(typeof(GardenCombat), "PayAbilityCost", (Type[])null, (Type[])null);
					replaced++;
				}
				yield return op;
			}
			if (replaced != 1)
			{
				throw new InvalidOperationException("REX health-cost call changed; expected one native expenditure.");
			}
		}
	}

	[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
	private static class CloneStats
	{
		private static readonly PropertyInfo Damage = AccessTools.Property(typeof(CharacterBody), "damage");

		private static void Postfix(CharacterBody __instance)
		{
			if (NetworkServer.active && Object.op_Implicit((Object)(object)__instance.master))
			{
				GardenClone component = ((Component)__instance.master).GetComponent<GardenClone>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.Owner) && Object.op_Implicit((Object)(object)component.Owner.Body))
				{
					Damage.SetValue(__instance, component.Owner.Body.damage * GardenSettings.CloneDamage.Value, null);
				}
			}
		}
	}

	internal static void Heal(RexDomain d, float fraction, Vector3 center, float radius)
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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_0121: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)d.Body) || !Object.op_Implicit((Object)(object)d.Body.teamComponent) || fraction <= 0f)
		{
			return;
		}
		List<CharacterBody> list = new List<CharacterBody>(CharacterBody.readOnlyInstancesList);
		foreach (CharacterBody item in list)
		{
			if (!Object.op_Implicit((Object)(object)item) || !Object.op_Implicit((Object)(object)item.healthComponent) || !item.healthComponent.alive || !Object.op_Implicit((Object)(object)item.teamComponent) || item.teamComponent.teamIndex != d.Body.teamComponent.teamIndex || !d.Inside(item))
			{
				continue;
			}
			Vector3 val = item.corePosition - center;
			if (!(((Vector3)(ref val)).sqrMagnitude > radius * radius) && (item.isPlayerControlled || (Object.op_Implicit((Object)(object)d.Clone) && !((Object)(object)item.master != (Object)(object)d.Clone))))
			{
				float num = item.healthComponent.Heal(item.healthComponent.fullHealth * fraction, default(ProcChainMask), true);
				if (num > 0f)
				{
					GardenSystem.Pulse(item.footPosition, 2);
				}
			}
		}
	}

	internal static void Summon(RexDomain d)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: 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_0122: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: 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_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || !d.Active || !Object.op_Implicit((Object)(object)d.Body.master) || !Object.op_Implicit((Object)(object)DirectorCore.instance))
		{
			return;
		}
		MasterCopySpawnCard val = MasterCopySpawnCard.FromMaster(d.Body.master, false, false, (Action<CharacterMaster>)delegate(CharacterMaster m)
		{
			m.cannotRevive = true;
			m.destroyOnBodyDeath = true;
			GardenClone gardenClone = ((Component)m).gameObject.AddComponent<GardenClone>();
			gardenClone.Owner = d;
			m.onBodyStart += gardenClone.BodyStarted;
		});
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((SpawnCard)val).prefab))
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
			Plugin.Log.LogWarning((object)"Garden: native REX AI copy unavailable.");
			return;
		}
		GameObject val2 = new GameObject("Garden clone spawn anchor");
		Vector3 val3 = d.Body.footPosition + ((Component)d.Body).transform.right * 4f;
		Vector3 val4 = val3 + Vector3.up * 12f;
		Vector3 down = Vector3.down;
		LayerIndex world = LayerIndex.world;
		RaycastHit val5 = default(RaycastHit);
		val3 = ((!Physics.Raycast(val4, down, ref val5, 30f, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1) || !(((RaycastHit)(ref val5)).normal.y > 0.5f)) ? d.Body.footPosition : ((RaycastHit)(ref val5)).point);
		val2.transform.position = val3 + Vector3.up;
		try
		{
			DirectorPlacementRule val6 = new DirectorPlacementRule();
			val6.placementMode = (PlacementMode)0;
			val6.spawnOnTarget = val2.transform;
			DirectorSpawnRequest val7 = new DirectorSpawnRequest((SpawnCard)(object)val, val6, new Xoroshiro128Plus(Run.instance.runRNG.nextUlong));
			val7.teamIndexOverride = d.Body.teamComponent.teamIndex;
			val7.summonerBodyObject = ((Component)d.Body).gameObject;
			val7.ignoreTeamMemberLimit = true;
			GameObject val8 = DirectorCore.instance.TrySpawnObject(val7);
			if (Object.op_Implicit((Object)(object)val8))
			{
				d.Clone = val8.GetComponent<CharacterMaster>();
				if (Object.op_Implicit((Object)(object)d.Clone))
				{
					CharacterBody body = d.Clone.GetBody();
					if (Object.op_Implicit((Object)(object)body))
					{
						((Component)d.Clone).GetComponent<GardenClone>().BodyStarted(body);
					}
					GardenSystem.Pulse(val3, 1);
				}
			}
			else
			{
				Plugin.Log.LogWarning((object)"Garden: clone placement failed.");
			}
		}
		finally
		{
			Object.Destroy((Object)(object)val);
			Object.Destroy((Object)(object)val2);
		}
	}

	internal static void RemoveClone(RexDomain d)
	{
		CharacterMaster clone = d.Clone;
		d.Clone = null;
		Remove(clone);
	}

	internal static void Remove(CharacterMaster m)
	{
		if (NetworkServer.active && Object.op_Implicit((Object)(object)m))
		{
			m.cannotRevive = true;
			CharacterBody body = m.GetBody();
			if (Object.op_Implicit((Object)(object)body))
			{
				NetworkServer.Destroy(((Component)body).gameObject);
			}
			NetworkServer.Destroy(((Component)m).gameObject);
		}
	}

	internal static void PayAbilityCost(HealthComponent health, DamageInfo damage)
	{
		RexDomain rexDomain = ((Object.op_Implicit((Object)(object)health) && Object.op_Implicit((Object)(object)health.body)) ? ((Component)health.body).GetComponent<RexDomain>() : null);
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)rexDomain) || !rexDomain.Active)
		{
			health.TakeDamage(damage);
			return;
		}
		damage.damage = GardenRules.Cost(damage.damage, GardenSettings.Cost.Value);
		float health2 = health.health;
		health.TakeDamage(damage);
		if (!damage.rejected)
		{
			rexDomain.SpentHealth(Mathf.Max(0f, health2 - health.health));
		}
	}
}
public sealed class GardenClone : MonoBehaviour
{
	internal RexDomain Owner;

	private float nextStats;

	private float lastDamage = -1f;

	private CharacterMaster master;

	private CharacterBody body;

	internal void BodyStarted(CharacterBody b)
	{
		if (Object.op_Implicit((Object)(object)b))
		{
			body = b;
			DeathRewards component = ((Component)b).GetComponent<DeathRewards>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.goldReward = 0u;
				component.expReward = 0u;
			}
			if (!b.HasBuff(Buffs.HiddenInvincibility))
			{
				b.AddBuff(Buffs.HiddenInvincibility);
			}
			b.MarkAllStatsDirty();
		}
	}

	private void FixedUpdate()
	{
		if (!NetworkServer.active)
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)master))
		{
			master = ((Component)this).GetComponent<CharacterMaster>();
		}
		if (!Object.op_Implicit((Object)(object)Owner) || !Owner.Active)
		{
			GardenCombat.Remove(master);
		}
		else if (!(Time.time < nextStats))
		{
			nextStats = Time.time + 1f;
			float num = Owner.Body.damage * GardenSettings.CloneDamage.Value;
			if (Object.op_Implicit((Object)(object)body) && num != lastDamage)
			{
				lastDamage = num;
				body.MarkAllStatsDirty();
			}
		}
	}

	private void OnDestroy()
	{
		CharacterMaster component = ((Component)this).GetComponent<CharacterMaster>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.onBodyStart -= BodyStarted;
		}
	}
}
internal sealed class GardenGrowth
{
	[HarmonyPatch(typeof(TreebotFlower2Projectile), "OnExit")]
	private static class SafeOwnedFlowerExit
	{
		private static void Prefix(TreebotFlower2Projectile __instance, List<CharacterBody> ___rootedBodies)
		{
			if (___rootedBodies == null || !Object.op_Implicit((Object)(object)((EntityState)__instance).outer) || !Object.op_Implicit((Object)(object)((Component)((EntityState)__instance).outer).GetComponent<GardenGrowthFlower>()))
			{
				return;
			}
			for (int num = ___rootedBodies.Count - 1; num >= 0; num--)
			{
				if (!Object.op_Implicit((Object)(object)___rootedBodies[num]))
				{
					___rootedBodies.RemoveAt(num);
				}
			}
		}
	}

	private static GameObject prefab;

	private readonly List<GameObject> flowers = new List<GameObject>(8);

	private float nextCast;

	private int sequence;

	internal void Tick(RexDomain domain)
	{
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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)
		if (!NetworkServer.active || !domain.Active || Time.time < nextCast)
		{
			return;
		}
		nextCast = Time.time + GardenSettings.GrowthInterval.Value;
		for (int num = flowers.Count - 1; num >= 0; num--)
		{
			if (!Object.op_Implicit((Object)(object)flowers[num]))
			{
				flowers.RemoveAt(num);
			}
		}
		if (flowers.Count >= GardenSettings.GrowthLimit.Value || !Object.op_Implicit((Object)(object)ProjectileManager.instance))
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			prefab = ProjectileCatalog.GetProjectilePrefab(ProjectileCatalog.FindProjectileIndex("TreebotFlower2"));
		}
		if (Object.op_Implicit((Object)(object)prefab) && FindGround(domain, out var point))
		{
			GameObject val = ProjectileManager.instance.FireProjectileImmediateServer(new FireProjectileInfo
			{
				projectilePrefab = prefab,
				owner = ((Component)domain.Body).gameObject,
				position = point,
				rotation = Quaternion.identity,
				damage = domain.Body.damage * 2f,
				crit = domain.Body.RollCrit(),
				force = 0f
			}, (NetworkConnection)null, (ushort)0, 0.0);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.AddComponent<GardenGrowthFlower>();
				flowers.Add(val);
			}
		}
	}

	private bool FindGround(RexDomain domain, out Vector3 point)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: 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_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: 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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		float radius = domain.State.Cast.Radius;
		Vector3 center = domain.State.Cast.Center;
		RaycastHit val6 = default(RaycastHit);
		for (int i = 0; i < 6; i++)
		{
			int num = sequence++;
			float num2 = (float)num * 2.399963f + (float)domain.State.Cast.CastId * 0.73f;
			float num3 = radius * 0.88f * Mathf.Sqrt(Mathf.Repeat(((float)num + 0.5f) * 0.618034f, 1f));
			Vector3 val = center + new Vector3(Mathf.Cos(num2) * num3, 0f, Mathf.Sin(num2) * num3);
			if (i == 0 && num % 2 == 0)
			{
				ReadOnlyCollection<CharacterBody> readOnlyInstancesList = CharacterBody.readOnlyInstancesList;
				float num4 = float.PositiveInfinity;
				Vector3 val2 = val;
				for (int j = 0; j < readOnlyInstancesList.Count; j++)
				{
					CharacterBody val3 = readOnlyInstancesList[j];
					if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.healthComponent) && val3.healthComponent.alive && Object.op_Implicit((Object)(object)val3.teamComponent) && domain.Inside(val3) && TeamManager.IsTeamEnemy(domain.Body.teamComponent.teamIndex, val3.teamComponent.teamIndex))
					{
						Vector3 val4 = val3.footPosition - val2;
						float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
						if (sqrMagnitude < num4)
						{
							num4 = sqrMagnitude;
							val = val3.footPosition;
						}
					}
				}
			}
			Vector3 val5 = val + Vector3.up * radius;
			Vector3 down = Vector3.down;
			float num5 = radius * 2f;
			LayerIndex world = LayerIndex.world;
			if (!Physics.Raycast(val5, down, ref val6, num5, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1) || ((RaycastHit)(ref val6)).normal.y < 0.55f)
			{
				continue;
			}
			point = ((RaycastHit)(ref val6)).point + Vector3.up * 0.08f;
			Vector3 val7 = point - center;
			if (((Vector3)(ref val7)).sqrMagnitude > radius * radius * 0.94f)
			{
				continue;
			}
			bool flag = false;
			float num6 = Mathf.Min(10f, radius * 0.25f);
			foreach (GameObject flower in flowers)
			{
				if (Object.op_Implicit((Object)(object)flower))
				{
					Vector3 val8 = flower.transform.position - point;
					if (((Vector3)(ref val8)).sqrMagnitude < num6 * num6)
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				return true;
			}
		}
		point = Vector3.zero;
		return false;
	}

	internal void Clear()
	{
		foreach (GameObject flower in flowers)
		{
			if (Object.op_Implicit((Object)(object)flower))
			{
				NetworkServer.Destroy(flower);
			}
		}
		flowers.Clear();
		nextCast = 0f;
		sequence = 0;
	}
}
public sealed class GardenGrowthFlower : MonoBehaviour
{
}
internal static class GardenProjectileRegistry
{
	[HarmonyPatch(typeof(ProjectileController), "Awake")]
	private static class Register
	{
		private static void Postfix(ProjectileController __instance)
		{
			Projectiles.Add(__instance);
		}
	}

	[HarmonyPatch(typeof(ProjectileController), "OnDestroy")]
	private static class Remove
	{
		private static void Prefix(ProjectileController __instance)
		{
			Projectiles.Remove(__instance);
		}
	}

	internal static readonly HashSet<ProjectileController> Projectiles = new HashSet<ProjectileController>();

	internal static void Initialize()
	{
		ProjectileController[] array = Object.FindObjectsOfType<ProjectileController>();
		foreach (ProjectileController item in array)
		{
			Projectiles.Add(item);
		}
	}
}
internal static class GardenProjection
{
	private sealed class Frame
	{
		internal Camera Probe;

		internal RenderTexture Normals;

		internal GardenVisual Owner;

		internal PostProcessLayer Layer;

		internal Camera Camera;

		internal CommandBuffer Composite;

		internal PropertySheetFactory Sheets;
	}

	[HarmonyPatch(typeof(PostProcessLayer), "OnPreCull")]
	private static class PrepareDomainCamera
	{
		[HarmonyPriority(0)]
		private static void Prefix(PostProcessLayer __instance)
		{
			try
			{
				Prepare(((Component)__instance).GetComponent<Camera>(), __instance);
			}
			catch (Exception ex)
			{
				if (!reported)
				{
					reported = true;
					Plugin.Log.LogError((object)("Domain projection camera failed; disabled for this session: " + ex));
				}
				Release();
				attempted = true;
			}
		}
	}

	private static readonly Dictionary<Camera, Frame> frames = new Dictionary<Camera, Frame>();

	private static Shader projection;

	private static Shader worldNormals;

	private static bool attempted;

	private static bool reported;

	internal static bool Supported
	{
		get
		{
			Ensure();
			if (Object.op_Implicit((Object)(object)projection))
			{
				return Object.op_Implicit((Object)(object)worldNormals);
			}
			return false;
		}
	}

	private static Shader Load(string resource, string path)
	{
		AssetBundle val = null;
		try
		{
			using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(resource))
			{
				if (stream == null)
				{
					throw new InvalidOperationException("Missing shader resource " + resource);
				}
				byte[] array = new byte[(int)stream.Length];
				int i;
				int num;
				for (i = 0; i < array.Length; i += num)
				{
					if ((num = stream.Read(array, i, array.Length - i)) <= 0)
					{
						break;
					}
				}
				if (i != array.Length)
				{
					throw new EndOfStreamException();
				}
				val = AssetBundle.LoadFromMemory(array);
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Shader bundle did not load.");
			}
			Shader val2 = val.LoadAsset<Shader>(path);
			if (!Object.op_Implicit((Object)(object)val2) || !val2.isSupported)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
				throw new InvalidOperationException("Shader unsupported: " + path);
			}
			return val2;
		}
		finally
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				val.Unload(false);
			}
		}
	}

	private static void Ensure()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Invalid comparison between Unknown and I4
		if (attempted)
		{
			return;
		}
		attempted = true;
		if ((int)SystemInfo.graphicsDeviceType != 2)
		{
			Plugin.Log.LogWarning((object)"Domain projection requires D3D11; using botanical mesh fallback.");
			return;
		}
		try
		{
			projection = Load("GardenOfSacrifice.GardenProjection", "assets/survivordomains/gardenprojection.shader");
			worldNormals = Load("GardenOfSacrifice.GardenNormals", "assets/survivordomains/gardennormals.shader");
			Plugin.Log.LogInfo((object)"Garden of Sacrifice: camera-local botanical paradise before transparent effects; gameplay-excluded scenery probe.");
		}
		catch (Exception ex)
		{
			if (Object.op_Implicit((Object)(object)projection))
			{
				Object.Destroy((Object)(object)projection);
			}
			projection = null;
			Plugin.Log.LogError((object)("Domain projection unavailable: " + ex));
		}
	}

	internal static void Prepare(Camera camera, PostProcessLayer layer)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Expected O, but got Unknown
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: 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_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_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: 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_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_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: 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_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_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: 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_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: 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_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: 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_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_0435: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0483: Unknown result type (might be due to invalid IL or missing references)
		//IL_0488: Unknown result type (might be due to invalid IL or missing references)
		//IL_051c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_0579: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: 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_05df: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_060c: Unknown result type (might be due to invalid IL or missing references)
		//IL_060e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0645: Unknown result type (might be due to invalid IL or missing references)
		//IL_065c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0687: Unknown result type (might be due to invalid IL or missing references)
		//IL_0695: Unknown result type (might be due to invalid IL or missing references)
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)camera) || ((Object)camera).name != "Scene Camera")
		{
			return;
		}
		GardenVisual gardenVisual = ((camera.stereoEnabled || camera.orthographic) ? null : GardenVisual.ForCamera(camera));
		if (Object.op_Implicit((Object)(object)gardenVisual) && gardenVisual.RealmAge < gardenVisual.RealmOpening * 0.2f)
		{
			gardenVisual = null;
		}
		Frame value;
		if (!Object.op_Implicit((Object)(object)gardenVisual) || !Supported)
		{
			if (frames.TryGetValue(camera, out value))
			{
				layer.OnVolumeSettingsChanged();
				Dispose(value);
				frames.Remove(camera);
			}
			return;
		}
		if (!frames.TryGetValue(camera, out value))
		{
			GameObject val = new GameObject("Domain world-only normals probe");
			((Object)val).hideFlags = (HideFlags)61;
			Frame frame = new Frame();
			frame.Probe = val.AddComponent<Camera>();
			frame.Layer = layer;
			frame.Camera = camera;
			frame.Sheets = new PropertySheetFactory();
			CommandBuffer val2 = new CommandBuffer();
			val2.name = "Garden of Sacrifice botanical world projection";
			frame.Composite = val2;
			value = frame;
			((Behaviour)value.Probe).enabled = false;
			camera.AddCommandBuffer((CameraEvent)16, value.Composite);
			frames.Add(camera, value);
			layer.OnVolumeSettingsChanged();
		}
		if ((Object)(object)value.Owner != (Object)(object)gardenVisual)
		{
			value.Owner = gardenVisual;
			layer.OnVolumeSettingsChanged();
		}
		int num = Mathf.Max(1, camera.pixelWidth);
		int num2 = Mathf.Max(1, camera.pixelHeight);
		if (!Object.op_Implicit((Object)(object)value.Normals) || ((Texture)value.Normals).width != num || ((Texture)value.Normals).height != num2)
		{
			if (Object.op_Implicit((Object)(object)value.Normals))
			{
				value.Normals.Release();
				Object.Destroy((Object)(object)value.Normals);
			}
			value.Normals = new RenderTexture(num, num2, 24, (RenderTextureFormat)0, (RenderTextureReadWrite)1);
			((Object)value.Normals).name = "Domain world depth and normals";
			((Texture)value.Normals).filterMode = (FilterMode)0;
			value.Normals.Create();
			layer.OnVolumeSettingsChanged();
		}
		Camera probe = value.Probe;
		probe.CopyFrom(camera);
		((Behaviour)probe).enabled = false;
		((Component)probe).transform.SetPositionAndRotation(((Component)camera).transform.position, ((Component)camera).transform.rotation);
		probe.cullingMask = camera.cullingMask;
		probe.renderingPath = (RenderingPath)1;
		probe.allowHDR = false;
		probe.allowMSAA = false;
		probe.depthTextureMode = (DepthTextureMode)0;
		probe.clearFlags = (CameraClearFlags)2;
		probe.backgroundColor = new Color(0.5f, 0.5f, 1f, 1f);
		probe.targetTexture = value.Normals;
		probe.rect = new Rect(0f, 0f, 1f, 1f);
		GardenScenery.Render(probe, worldNormals);
		CommandBuffer composite = value.Composite;
		composite.Clear();
		int num3 = Shader.PropertyToID("_GardenOpaqueCopy");
		composite.GetTemporaryRT(num3, num, num2, 0, (FilterMode)1, (RenderTextureFormat)(camera.allowHDR ? 9 : 7));
		composite.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), RenderTargetIdentifier.op_Implicit(num3));
		Ray val3 = camera.ViewportPointToRay(new Vector3(0f, 0f, 0f));
		Vector3 direction = ((Ray)(ref val3)).direction;
		Ray val4 = camera.ViewportPointToRay(new Vector3(1f, 0f, 0f));
		Vector3 direction2 = ((Ray)(ref val4)).direction;
		Ray val5 = camera.ViewportPointToRay(new Vector3(0f, 1f, 0f));
		Vector3 direction3 = ((Ray)(ref val5)).direction;
		Vector3 forward = ((Component)camera).transform.forward;
		direction /= Mathf.Max(0.0001f, Vector3.Dot(direction, forward));
		direction2 /= Mathf.Max(0.0001f, Vector3.Dot(direction2, forward));
		direction3 /= Mathf.Max(0.0001f, Vector3.Dot(direction3, forward));
		composite.SetGlobalVector("_GdnRayOrigin", Vector4.op_Implicit(direction));
		composite.SetGlobalVector("_GdnRayRight", Vector4.op_Implicit(direction2 - direction));
		composite.SetGlobalVector("_GdnRayUp", Vector4.op_Implicit(direction3 - direction));
		composite.SetGlobalVector("_GdnCamera", Vector4.op_Implicit(((Component)camera).transform.position));
		Vector3 position = ((Component)gardenVisual).transform.position;
		composite.SetGlobalVector("_GdnDomain", new Vector4(position.x, position.y, position.z, gardenVisual.RealmRadius));
		float realmAge = gardenVisual.RealmAge;
		float realmOpening = gardenVisual.RealmOpening;
		float num4 = 1f - CastTimeline.Expansion(Vector3.Distance(((Component)camera).transform.position, position) / gardenVisual.RealmRadius - 0.92f, 0.07f);
		float num5 = Mathf.Clamp01(GardenSettings.Intensity.Value) * gardenVisual.Envelope * CastTimeline.Expansion(realmAge - realmOpening * 0.2f, realmOpening * 0.45f) * num4;
		SceneCamera component = ((Component)camera).GetComponent<SceneCamera>();
		CharacterBody val6 = ((Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.cameraRigController)) ? component.cameraRigController.targetBody : null);
		Vector3 val7 = (Object.op_Implicit((Object)(object)val6) ? val6.footPosition : position);
		composite.SetGlobalVector("_GdnState", new Vector4(realmAge, num5, gardenVisual.CollapseProgress, 0f));
		composite.SetGlobalVector("_GdnCosmic", new Vector4((float)GardenSettings.Quality.Value, Plugin.Clamp(GardenSettings.Intensity.Value, 0f, 1.5f), gardenVisual.CollapseProgress, 0f));
		composite.SetGlobalVector("_GdnFoot", new Vector4(0f, 0f, (float)((Object.op_Implicit((Object)(object)val6) && Object.op_Implicit((Object)(object)val6.characterMotor) && val6.characterMotor.isGrounded) ? 1 : 0), 0f));
		composite.SetGlobalVector("_GdnRight", Vector4.op_Implicit(((Component)camera).transform.right));
		composite.SetGlobalVector("_GdnUp", Vector4.op_Implicit(((Component)camera).transform.up));
		composite.SetGlobalVector("_GdnForward", Vector4.op_Implicit(forward));
		composite.SetGlobalVector("_GdnParams", new Vector4(camera.farClipPlane, realmOpening, Plugin.Clamp(GardenSettings.Intensity.Value, 0f, 1.5f), 0f));
		composite.SetGlobalTexture("_GdnGardenNormals", RenderTargetIdentifier.op_Implicit((Texture)(object)value.Normals));
		composite.SetGlobalVector("_GdnGrandHit", new Vector4(1f, val7.x, val7.y, val7.z));
		RuntimeUtilities.BlitFullscreenTriangle(composite, RenderTargetIdentifier.op_Implicit(num3), RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)3), value.Sheets.Get(projection), 0, false, (Rect?)null);
		composite.ReleaseTemporaryRT(num3);
	}

	private static void Dispose(Frame frame)
	{
		if (Object.op_Implicit((Object)(object)frame.Camera) && frame.Composite != null)
		{
			frame.Camera.RemoveCommandBuffer((CameraEvent)16, frame.Composite);
		}
		if (frame.Composite != null)
		{
			frame.Composite.Dispose();
		}
		if (frame.Sheets != null)
		{
			frame.Sheets.Release();
		}
		if (Object.op_Implicit((Object)(object)frame.Probe))
		{
			frame.Probe.targetTexture = null;
			Object.Destroy((Object)(object)((Component)frame.Probe).gameObject);
		}
		if (Object.op_Implicit((Object)(object)frame.Normals))
		{
			frame.Normals.Release();
			Object.Destroy((Object)(object)frame.Normals);
		}
	}

	internal static void ReleaseOwner(GardenVisual owner)
	{
		List<Camera> list = new List<Camera>();
		foreach (KeyValuePair<Camera, Frame> frame in frames)
		{
			if ((Object)(object)frame.Value.Owner == (Object)(object)owner || !Object.op_Implicit((Object)(object)frame.Key))
			{
				if (Object.op_Implicit((Object)(object)frame.Value.Layer))
				{
					frame.Value.Layer.OnVolumeSettingsChanged();
				}
				Dispose(frame.Value);
				list.Add(frame.Key);
			}
		}
		foreach (Camera item in list)
		{
			frames.Remove(item);
		}
	}

	internal static void Release()
	{
		foreach (Frame value in frames.Values)
		{
			if (Object.op_Implicit((Object)(object)value.Layer))
			{
				value.Layer.OnVolumeSettingsChanged();
			}
			Dispose(value);
		}
		frames.Clear();
		if (Object.op_Implicit((Object)(object)projection))
		{
			Object.Destroy((Object)(object)projection);
		}
		if (Object.op_Implicit((Object)(object)worldNormals))
		{
			Object.Destroy((Object)(object)worldNormals);
		}
		projection = (worldNormals = null);
		attempted = false;
	}
}
internal static class GardenRules
{
	internal static float Cost(float damage, float reduction)
	{
		return Math.Max(0f, damage) * (1f - Math.Max(0f, Math.Min(1f, reduction)));
	}

	internal static float Root(float duration, float bossDuration, bool boss, float interval, float remaining)
	{
		return Math.Max(0f, Math.Min(remaining, Math.Min(interval * 0.8f, boss ? Math.Min(duration, bossDuration) : duration)));
	}

	internal static bool Active(float age, float opening, float duration, bool ended)
	{
		if (!ended && age >= opening)
		{
			return age < opening + duration;
		}
		return false;
	}
}
internal static class GardenScenery
{
	private static readonly HashSet<Renderer> protectedRenderers = new HashSet<Renderer>();

	private static readonly List<Renderer> suppressed = new List<Renderer>();

	private static readonly List<Renderer> rendererBuffer = new List<Renderer>();

	private static readonly List<Component> interactables = new List<Component>();

	private static float nextScan;

	private static void Protect(Component component)
	{
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		rendererBuffer.Clear();
		component.GetComponentsInChildren<Renderer>(true, rendererBuffer);
		foreach (Renderer item in rendererBuffer)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				protectedRenderers.Add(item);
			}
		}
	}

	internal static void Render(Camera probe, Shader shader)
	{
		protectedRenderers.Clear();
		foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
		{
			Protect((Component)(object)readOnlyInstances);
			if (Object.op_Implicit((Object)(object)readOnlyInstances) && Object.op_Implicit((Object)(object)readOnlyInstances.modelLocator) && Object.op_Implicit((Object)(object)readOnlyInstances.modelLocator.modelTransform))
			{
				Protect((Component)(object)readOnlyInstances.modelLocator.modelTransform);
			}
		}
		foreach (ProjectileController projectile in GardenProjectileRegistry.Projectiles)
		{
			Protect((Component)(object)projectile);
		}
		foreach (IInteractable instances in InterfaceInstanceTracker<IInteractable>.GetInstancesList())
		{
			Protect((Component)(object)((instances is Component) ? instances : null));
		}
		foreach (PickupDropletController instances2 in InstanceTracker.GetInstancesList<PickupDropletController>())
		{
			Protect((Component)(object)instances2);
		}
		foreach (SceneExitController instances3 in InstanceTracker.GetInstancesList<SceneExitController>())
		{
			Protect((Component)(object)instances3);
		}
		if (Time.unscaledTime >= nextScan)
		{
			nextScan = Time.unscaledTime + 0.2f;
			interactables.Clear();
			interactables.AddRange((IEnumerable<Component>)(object)Object.FindObjectsOfType<ShopTerminalBehavior>());
			interactables.AddRange((IEnumerable<Component>)(object)Object.FindObjectsOfType<Highlight>());
		}
		foreach (Component interactable in interactables)
		{
			Protect(interactable);
			Highlight val = (Highlight)(object)((interactable is Highlight) ? interactable : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.targetRenderer))
			{
				protectedRenderers.Add(val.targetRenderer);
			}
		}
		try
		{
			foreach (Renderer protectedRenderer in protectedRenderers)
			{
				if (Object.op_Implicit((Object)(object)protectedRenderer) && !protectedRenderer.forceRenderingOff)
				{
					suppressed.Add(protectedRenderer);
					protectedRenderer.forceRenderingOff = true;
				}
			}
			probe.RenderWithShader(shader, "RenderType");
		}
		finally
		{
			foreach (Renderer item in suppressed)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					item.forceRenderingOff = false;
				}
			}
			suppressed.Clear();
			protectedRenderers.Clear();
		}
	}

	internal static void Clear()
	{
		interactables.Clear();
		protectedRenderers.Clear();
		rendererBuffer.Clear();
		nextScan = 0f;
	}
}
internal static class GardenSettings
{
	internal static ConfigEntry<float> Radius;

	internal static ConfigEntry<float> Opening;

	internal static ConfigEntry<float> Duration;

	internal static ConfigEntry<float> Collapse;

	internal static ConfigEntry<float> Charge;

	internal static ConfigEntry<float> Heal;

	internal static ConfigEntry<float> Cost;

	internal static ConfigEntry<float> GrowthInterval;

	internal static ConfigEntry<float> BloomHeal;

	internal static ConfigEntry<float> BloomCooldown;

	internal static ConfigEntry<float> BloomRadius;

	internal static ConfigEntry<float> FinalHeal;

	internal static ConfigEntry<float> CloneDamage;

	internal static ConfigEntry<float> Intensity;

	internal static ConfigEntry<int> Quality;

	internal static ConfigEntry<int> GrowthLimit;

	internal static ConfigEntry<KeyCode> Key;

	internal static void Bind(ConfigFile c)
	{
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Expected O, but got Unknown
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Expected O, but got Unknown
		Radius = F(c, "Radius", 62.5f, 2f, 150f, "Stationary garden radius in meters.");
		Opening = F(c, "ExpansionDuration", 3.5f, 1f, 12f, "Seed, blooming wave and forest growth in seconds.");
		Duration = F(c, "ActiveDuration", 34f, 1f, 90f, "Active garden seconds after expansion.");
		Collapse = F(c, "CollapseDuration", 2f, 0.5f, 8f, "Final bloom and dissolution seconds.");
		Charge = F(c, "DamageToCharge", 100f, 1f, 10000f, "Level-scaled base damage multiples.");
		Heal = F(c, "HealingPerSecond", 0.02f, 0f, 0.25f, "Fraction of maximum health per second to allied players and this garden's clone.");
		Cost = F(c, "HealthCostReduction", 0.5f, 0f, 1f, "Reduction only at native REX ability health-expenditure calls.");
		GrowthInterval = F(c, "TanglingGrowthInterval", 0.75f, 0.35f, 5f, "Seconds between scattered native R casts; skips a cast when the live-flower cap is reached.");
		GrowthLimit = c.Bind<int>("REX", "MaxTanglingGrowthFlowers", 8, new ConfigDescription("Maximum concurrent domain R flowers; limits native searches, tendrils and heal effects.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 12), new object[0]));
		BloomHeal = F(c, "SacrificialBloomHeal", 0.01f, 0f, 0.2f, "Nearby ally healing fraction after actual ability health expenditure.");
		BloomCooldown = F(c, "SacrificialBloomCooldown", 1f, 0.1f, 10f, "Minimum seconds between blooms.");
		BloomRadius = F(c, "SacrificialBloomRadius", 14f, 1f, 60f, "Nearby allies must also be inside the garden.");
		FinalHeal = F(c, "FinalBloomHeal", 0.1f, 0f, 1f, "One healing burst on natural expiry only.");
		CloneDamage = F(c, "CloneDamageMultiplier", 0.5f, 0f, 2f, "Clone damage stat relative to caster, no item or equipment duplication.");
		Intensity = F(c, "EnvironmentalIntensity", 1f, 0f, 1f, "Garden projection strength.");
		Quality = c.Bind<int>("REX", "VisualQuality", 1, new ConfigDescription("0 low, 1 balanced, 2 high; batched foliage density and update rate.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2), new object[0]));
		Key = c.Bind<KeyCode>("REX", "ActivationKey", (KeyCode)116, "Additional charged domain ability.");
	}

	private static ConfigEntry<float> F(ConfigFile c, string key, float value, float min, float max, string description)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		return c.Bind<float>("REX", key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), new object[0]));
	}
}
internal static class GardenSystem
{
	private const short RequestId = 28260;

	private const short StateId = 28261;

	private const short AbsorbId = 28262;

	private static bool registered;

	private static NetworkClient client;

	internal static void Initialize(ConfigFile config)
	{
		GardenSettings.Bind(config);
		CharacterBody.onBodyStartGlobal += Attach;
		GlobalEventManager.onServerDamageDealt += Damage;
	}

	private static void Attach(CharacterBody body)
	{
		if (Object.op_Implicit((Object)(object)body) && body.isPlayerControlled && ((Object)body).name.StartsWith("TreebotBody", StringComparison.Ordinal) && !Object.op_Implicit((Object)(object)((Component)body).GetComponent<RexDomain>()))
		{
			((Component)body).gameObject.AddComponent<RexDomain>();
		}
	}

	private static void Damage(DamageReport report)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkServer.active && report != null && Object.op_Implicit((Object)(object)report.attackerBody) && report.damageInfo != null && !report.damageInfo.rejected && TeamManager.IsTeamEnemy(report.attackerTeamIndex, report.victimTeamIndex))
		{
			RexDomain component = ((Component)report.attackerBody).GetComponent<RexDomain>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.AddCharge(Mathf.Min(report.damageDealt, report.combinedHealthBeforeDamage));
			}
		}
	}

	internal static void Update()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		if (NetworkServer.active && !registered)
		{
			NetworkServer.RegisterHandler((short)28260, new NetworkMessageDelegate(ReceiveRequest));
			registered = true;
		}
		if (!NetworkServer.active)
		{
			registered = false;
		}
		NetworkClient val = (Object.op_Implicit((Object)(object)NetworkManager.singleton) ? NetworkManager.singleton.client : null);
		if (val != client)
		{
			if (client != null)
			{
				client.UnregisterHandler((short)28261);
				client.UnregisterHandler((short)28262);
			}
			client = val;
			if (client != null)
			{
				client.RegisterHandler((short)28261, new NetworkMessageDelegate(ReceiveState));
				client.RegisterHandler((short)28262, new NetworkMessageDelegate(ReceiveAbsorb));
			}
		}
	}

	internal static void Request(CharacterBody body)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkServer.active)
		{
			((Component)body).GetComponent<RexDomain>().ActivateServer();
		}
		else if (client != null)
		{
			client.Send((short)28260, (MessageBase)(object)new DomainMessage
			{
				Body = ((NetworkBehaviour)body).netId
			});
		}
	}

	private static void ReceiveRequest(NetworkMessage message)
	{
		//IL_0055: 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)
		DomainMessage domainMessage = message.ReadMessage<DomainMessage>();
		foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
		{
			if (!Object.op_Implicit((Object)(object)readOnlyInstances) || ((NetworkBehaviour)readOnlyInstances).connectionToClient != message.conn || !Object.op_Implicit((Object)(object)readOnlyInstances.master))
			{
				continue;
			}
			CharacterBody body = readOnlyInstances.master.GetBody();
			if (Object.op_Implicit((Object)(object)body) && !(((NetworkBehaviour)body).netId != domainMessage.Body))
			{
				RexDomain component = ((Component)body).GetComponent<RexDomain>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.ActivateServer();
				}
				break;
			}
		}
	}

	private static void ReceiveState(NetworkMessage message)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		GardenState gardenState = message.ReadMessage<GardenState>();
		GameObject val = ClientScene.FindLocalObject(gardenState.Cast.Body);
		if (Object.op_Implicit((Object)(object)val))
		{
			Attach(val.GetComponent<CharacterBody>());
			RexDomain component = val.GetComponent<RexDomain>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Show(gardenState);
			}
		}
	}

	internal static void Broadcast(RexDomain owner, GardenState data)
	{
		NetworkServer.SendToAll((short)28261, (MessageBase)(object)data);
		owner.Show(data);
	}

	internal static void Pulse(Vector3 point, int kind)
	{
		//IL_000c: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		NetworkServer.SendToAll((short)28262, (MessageBase)(object)new GardenPulse
		{
			Point = point,
			Kind = kind
		});
		if (NetworkClient.active)
		{
			ShowPulse(point, kind);
		}
	}

	private static void ReceiveAbsorb(NetworkMessage message)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		GardenPulse gardenPulse = message.ReadMessage<GardenPulse>();
		if (!NetworkServer.active)
		{
			ShowPulse(gardenPulse.Point, gardenPulse.Kind);
		}
	}

	private static void ShowPulse(Vector3 point, int kind)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		foreach (GardenVisual instance in GardenVisual.Instances)
		{
			if (Object.op_Implicit((Object)(object)instance))
			{
				Vector3 val = ((Component)instance).transform.position - point;
				if (((Vector3)(ref val)).sqrMagnitude < instance.RealmRadius * instance.RealmRadius)
				{
					instance.Pulse(point, kind);
				}
			}
		}
	}

	internal static void Shutdown()
	{
		CharacterBody.onBodyStartGlobal -= Attach;
		GlobalEventManager.onServerDamageDealt -= Damage;
		RexDomain[] array = Object.FindObjectsOfType<RexDomain>();
		foreach (RexDomain rexDomain in array)
		{
			Object.DestroyImmediate((Object)(object)rexDomain);
		}
		GardenVisual[] array2 = GardenVisual.Instances.ToArray();
		foreach (GardenVisual gardenVisual in array2)
		{
			if (Object.op_Implicit((Object)(object)gardenVisual))
			{
				Object.DestroyImmediate((Object)(object)((Component)gardenVisual).gameObject);
			}
		}
		GardenProjection.Release();
		if (registered)
		{
			NetworkServer.UnregisterHandler((short)28260);
		}
		registered = false;
		if (client != null)
		{
			client.UnregisterHandler((short)28261);
			client.UnregisterHandler((short)28262);
		}
		client = null;
	}
}
public sealed class GardenPulse : MessageBase
{
	public Vector3 Point;

	public int Kind;

	public override void Serialize(NetworkWriter w)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		w.Write(Point);
		w.Write((byte)Kind);
	}

	public override void Deserialize(NetworkReader r)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Point = r.ReadVector3();
		Kind = r.ReadByte();
	}
}
internal sealed class GardenVegetation
{
	private sealed class Batch
	{
		private struct Group
		{
			internal int First;

			internal int End;

			internal Vector3 Anchor;

			internal float Arrival;
		}

		internal RealmMesh Mesh;

		private Vector3[] local;

		private Vector3[] current;

		private float[] windX;

		private float[] windZ;

		private readonly List<Group> groups = new List<Group>();

		private float nextMotion;

		private bool settled;

		internal Batch(Transform parent, string name)
		{
			Mesh = new RealmMesh(parent, name, additive: false, 3080);
		}

		internal void Record(int first, V