Decompiled source of Codex Frozen Realms v0.1.0

BepInEx/plugins/Codex_Arena_Sol/CodexArenaSol.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexArenaSol
{
	[BepInPlugin("codex.outward.arena.sol", "Codex - Sol Artificial da Arena", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private GameObject _root;

		private Collider _support;

		private float _nextScan;

		private float _nextBuild;

		private List<Character> _players = new List<Character>();

		private void Awake()
		{
			SceneManager.sceneLoaded += SceneLoaded;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[ArenaSol] 1.0.0;sol sempre aceso,18m acima do piso,alcance60m;sem alterar cidade/combate/ciclo de horario.");
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
				_nextScan = 0f;
				_nextBuild = 0f;
			}
		}

		private void Update()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextScan)
			{
				return;
			}
			_nextScan = Time.unscaledTime + 0.25f;
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name != "CierzoTutorial")
			{
				Cleanup();
				return;
			}
			if ((Object)(object)_root != (Object)null && (Object)(object)_support == (Object)null)
			{
				Cleanup();
			}
			bool flag = HasViewer(name);
			if ((Object)(object)_root == (Object)null && flag && Time.unscaledTime >= _nextBuild)
			{
				_nextBuild = Time.unscaledTime + 2f;
				TryBuild();
			}
			if ((Object)(object)_root != (Object)null && _root.activeSelf != flag)
			{
				_root.SetActive(flag);
			}
		}

		private bool HasViewer(string scene)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			CharacterManager instance = CharacterManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			_players.Clear();
			instance.FindCharactersInRange(new Vector3(-17f, 255f, 1874.7f), 260f, ref _players);
			foreach (Character player in _players)
			{
				if ((Object)(object)player != (Object)null && SolarDesign.Visible(scene, player.IsLocalPlayer, ((Component)player).transform.position.x, ((Component)player).transform.position.y, ((Component)player).transform.position.z))
				{
					return true;
				}
			}
			return false;
		}

		private void TryBuild()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_010a: 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)
			GameObject val = GameObject.Find("CampoMecanico_Arena_Piso");
			Collider val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Collider>());
			RaycastHit val3 = default(RaycastHit);
			if ((Object)(object)val2 == (Object)null || !val2.enabled || !val.activeInHierarchy || !val2.Raycast(new Ray(new Vector3(-17f, 280f, 1874.7f), Vector3.down), ref val3, 35f) || ((RaycastHit)(ref val3)).point.y <= 220f)
			{
				return;
			}
			try
			{
				_root = new GameObject("Codex_Arena_Sol_Artificial");
				SceneManager.MoveGameObjectToScene(_root, val.scene);
				_root.SetActive(false);
				_root.transform.position = ((RaycastHit)(ref val3)).point + Vector3.up * 18f;
				_support = val2;
				_root.AddComponent<SolarVisual>().Build();
				((BaseUnityPlugin)this).Logger.LogMessage((object)("[ArenaSol] PRONTO;centro=" + ((object)_root.transform.position/*cast due to .constrained prefix*/).ToString() + ";piso=" + ((Object)val2).name + ";luz pontual60m/intensidade3.2,sem sombras;sempre aceso na arena;oculto no tutorial inferior."));
			}
			catch (Exception ex)
			{
				Cleanup();
				_nextBuild = Time.unscaledTime + 10f;
				((BaseUnityPlugin)this).Logger.LogError((object)("[ArenaSol] Falha isolada na iluminacao;cidade preservada: " + ex));
			}
		}

		private void Cleanup()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
				SolarVisual component = _root.GetComponent<SolarVisual>();
				if ((Object)(object)component != (Object)null)
				{
					component.ReleaseAssets();
				}
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_support = null;
			_players.Clear();
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= SceneLoaded;
			Cleanup();
		}
	}
	internal static class SolarDesign
	{
		internal const string SceneName = "CierzoTutorial";

		internal const string FloorName = "CampoMecanico_Arena_Piso";

		internal const float WorldX = -17f;

		internal const float WorldZ = 1874.7f;

		internal const float Height = 18f;

		internal const float Diameter = 3.2f;

		internal const float LightRange = 60f;

		internal const float LightIntensity = 3.2f;

		internal const float ViewRange = 230f;

		internal const float MinimumPlayerY = 220f;

		internal const int RingSegments = 72;

		internal const int TubeSegments = 8;

		internal static bool Visible(string scene, bool localPlayer, float x, float y, float z)
		{
			double num = x - -17f;
			double num2 = z - 1874.7f;
			if (scene == "CierzoTutorial" && localPlayer && y > 220f)
			{
				return num * num + num2 * num2 <= 52900.0;
			}
			return false;
		}

		internal static float[] RingVertices(float radius, float tube)
		{
			float[] array = new float[1728];
			for (int i = 0; i < 72; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					double num = (double)i * Math.PI * 2.0 / 72.0;
					double num2 = (double)j * Math.PI * 2.0 / 8.0;
					double num3 = (double)radius + (double)tube * Math.Cos(num2);
					int num4 = (i * 8 + j) * 3;
					array[num4] = (float)(num3 * Math.Cos(num));
					array[num4 + 1] = (float)((double)tube * Math.Sin(num2));
					array[num4 + 2] = (float)(num3 * Math.Sin(num));
				}
			}
			return array;
		}

		internal static int[] RingTriangles()
		{
			int[] array = new int[3456];
			int num = 0;
			for (int i = 0; i < 72; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					int num2 = i * 8 + j;
					int num3 = (i + 1) % 72 * 8 + j;
					int num4 = (i + 1) % 72 * 8 + (j + 1) % 8;
					int num5 = i * 8 + (j + 1) % 8;
					array[num++] = num2;
					array[num++] = num5;
					array[num++] = num3;
					array[num++] = num3;
					array[num++] = num5;
					array[num++] = num4;
				}
			}
			return array;
		}
	}
	internal sealed class SolarVisual : MonoBehaviour
	{
		private readonly List<Object> _owned = new List<Object>();

		internal void Build()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_017a: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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)
			Light obj = ((Component)this).gameObject.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = new Color(1f, 0.9f, 0.74f);
			obj.range = 60f;
			obj.intensity = 3.2f;
			obj.shadows = (LightShadows)0;
			obj.renderMode = (LightRenderMode)1;
			obj.cullingMask = -1;
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Shader Standard indisponivel.");
			}
			Material val2 = Own<Material>(new Material(val));
			((Object)val2).name = "ArenaSol_Nucleo_Dourado";
			val2.color = new Color(1f, 0.91f, 0.68f);
			val2.SetFloat("_Glossiness", 0.35f);
			val2.SetColor("_EmissionColor", new Color(3.5f, 2.45f, 1.12f));
			val2.EnableKeyword("_EMISSION");
			Texture2D val3 = (Texture2D)(object)(val2.mainTexture = (Texture)(object)SunSurface());
			val2.SetTexture("_EmissionMap", (Texture)(object)val3);
			GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj2).name = "ArenaSol_Nucleo";
			Collider component = obj2.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				component.enabled = false;
				Object.Destroy((Object)(object)component);
			}
			obj2.transform.SetParent(((Component)this).transform, false);
			obj2.transform.localScale = Vector3.one * 3.2f;
			Renderer component2 = obj2.GetComponent<Renderer>();
			component2.sharedMaterial = val2;
			component2.shadowCastingMode = (ShadowCastingMode)0;
			component2.receiveShadows = false;
			Material val5 = Own<Material>(new Material(val));
			((Object)val5).name = "ArenaSol_Aros_Cobre";
			val5.color = new Color(0.43f, 0.28f, 0.1f);
			val5.SetFloat("_Metallic", 0.75f);
			val5.SetFloat("_Glossiness", 0.4f);
			val5.SetColor("_EmissionColor", new Color(0.28f, 0.15f, 0.03f));
			val5.EnableKeyword("_EMISSION");
			Ring("ArenaSol_Aro_Interior", 2.15f, 0.1f, new Vector3(24f, 0f, 30f), val5);
			Ring("ArenaSol_Aro_Exterior", 2.65f, 0.08f, new Vector3(74f, 18f, -26f), val5);
		}

		private void Ring(string name, float radius, float tube, Vector3 rotation, Material material)
		{
			//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)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			float[] array = SolarDesign.RingVertices(radius, tube);
			Vector3[] array2 = (Vector3[])(object)new Vector3[array.Length / 3];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = new Vector3(array[i * 3], array[i * 3 + 1], array[i * 3 + 2]);
			}
			Mesh val = Own<Mesh>(new Mesh());
			((Object)val).name = name + "_Mesh";
			val.vertices = array2;
			val.triangles = SolarDesign.RingTriangles();
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(((Component)this).transform, false);
			val2.transform.localRotation = Quaternion.Euler(rotation);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
		}

		private Texture2D SunSurface()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					double num = (double)j * Math.PI * 2.0 / 128.0;
					double num2 = (double)i * Math.PI / 127.0;
					double num3 = Math.Sin(num2) * Math.Cos(num);
					double num4 = Math.Sin(num2) * Math.Sin(num);
					double num5 = Math.Cos(num2);
					double num6 = Math.Sin(num3 * 19.0 + num5 * 11.0) * Math.Sin(num4 * 16.0 - num5 * 13.0) + 0.4 * Math.Sin(num3 * 41.0 + num4 * 29.0);
					float num7 = (float)(0.8 + num6 * 0.12);
					array[i * 128 + j] = new Color(num7, num7 * 0.92f, num7 * 0.74f, 1f);
				}
			}
			Texture2D obj = Own<Texture2D>(new Texture2D(128, 128, (TextureFormat)4, true));
			((Object)obj).name = "ArenaSol_Superficie128";
			((Texture)obj).wrapMode = (TextureWrapMode)0;
			((Texture)obj).filterMode = (FilterMode)2;
			obj.SetPixels(array);
			obj.Apply(true, true);
			return obj;
		}

		private T Own<T>(T item) where T : Object
		{
			_owned.Add((Object)(object)item);
			return item;
		}

		internal void ReleaseAssets()
		{
			foreach (Object item in _owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			_owned.Clear();
		}

		private void OnDestroy()
		{
			ReleaseAssets();
		}
	}
}

BepInEx/plugins/Codex_Arena_Torretas/CodexArenaTorretas.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexTorretaRunica
{
	public static class ArenaCatalog
	{
		public const float CenterX = -17f;

		public const float CenterZ = 1874.7f;

		public const float AttackRadius = 40f;

		public const float BeamRange = 50f;

		public static readonly TurretSpec[] All = Create();

		private static TurretSpec[] Create()
		{
			TurretSpec[] array = new TurretSpec[8];
			int[] array2 = new int[4] { 0, 2, 3, 4 };
			float[] array3 = new float[4] { -21f, -7f, 7f, 21f };
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					TurretSpec turretSpec = TurretCatalog.All[array2[j]];
					string text = ((i == 0) ? "oeste" : "leste");
					array[i * 4 + j] = new TurretSpec(turretSpec.Id + "_" + text, turretSpec.Name + " - " + text, -1800 + ((i == 0) ? (-32) : 32), 78f + array3[j], turretSpec.Health, 50f, turretSpec.Damage, turretSpec.Impact, turretSpec.Warning, turretSpec.Fire, turretSpec.Cooldown, turretSpec.Element, turretSpec.Status, turretSpec.Buildup, turretSpec.Shape, turretSpec.Scale, turretSpec.Red, turretSpec.Green, turretSpec.Blue);
				}
			}
			return array;
		}

		public static bool IsCombatPosition(float x, float y, float z)
		{
			float num = x - -17f;
			float num2 = z - 1874.7f;
			if (y >= 200f && y <= 280f)
			{
				return num * num + num2 * num2 <= 1600f;
			}
			return false;
		}
	}
	internal static class ArenaPlacement
	{
		internal const string FloorName = "CampoMecanico_Arena_Piso";

		internal static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string reason;
			return TrySurface(position, out surface, out support, out reason);
		}

		internal unsafe static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support, out string reason)
		{
			//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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			surface = position;
			support = null;
			reason = null;
			GameObject val = GameObject.Find("CampoMecanico_Arena_Piso");
			Collider val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Collider>());
			if ((Object)(object)val2 == (Object)null)
			{
				reason = "Piso da arena ausente";
				return false;
			}
			if (!val2.enabled || !((Component)val2).gameObject.activeInHierarchy)
			{
				reason = "Piso da arena inativo";
				return false;
			}
			RaycastHit val3 = default(RaycastHit);
			if (!val2.Raycast(new Ray(new Vector3(position.x, 280f, position.z), Vector3.down), ref val3, 35f))
			{
				Vector3 val4 = position;
				reason = "Ray sem contato com piso da arena em " + ((object)(*(Vector3*)(&val4))/*cast due to .constrained prefix*/).ToString();
				return false;
			}
			if (((RaycastHit)(ref val3)).point.y <= 200f)
			{
				reason = "Piso abaixo da area elevada";
				return false;
			}
			int layer = ((Component)val2).gameObject.layer;
			if ((Global.GeneralEnvironmentMask & (1 << layer)) == 0)
			{
				reason = "Camada piso=" + layer + " fora da mascara ambiente=" + Global.GeneralEnvironmentMask;
				return false;
			}
			surface = ((RaycastHit)(ref val3)).point;
			support = val2;
			return true;
		}

		internal static bool SpotClear(Vector3 floor, Collider support)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string reason;
			return SpotClear(floor, support, out reason);
		}

		internal static bool SpotClear(Vector3 floor, Collider support, out string reason)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			reason = null;
			if ((Object)(object)support == (Object)null)
			{
				reason = "Sem apoio validado";
				return false;
			}
			Collider[] array = Physics.OverlapCapsule(floor + Vector3.up * 1.5f, floor + Vector3.up * 3.2f, 1.15f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)support)
				{
					reason = "Corpo bloqueado por " + ((Object)((Component)val).gameObject).name + " acima do pisoY=" + floor.y;
					return false;
				}
			}
			return true;
		}
	}
	internal sealed class ArenaPlayerCandidates
	{
		private static readonly Vector3 Center = new Vector3(-17f, 255f, 1874.7f);

		private List<Character> _arena = new List<Character>();

		private List<Character> _fallback = new List<Character>();

		private CharacterManager _manager;

		private int _frame = -1;

		internal List<Character> Query(Vector3 point, float radius)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			CharacterManager instance = CharacterManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Reset();
				return _arena;
			}
			Vector3 val = point - Center;
			if (((Vector3)(ref val)).magnitude + radius > 256f)
			{
				_fallback.Clear();
				instance.FindCharactersInRange(point, radius, ref _fallback);
				return _fallback;
			}
			if (_frame != Time.frameCount || (Object)(object)_manager != (Object)(object)instance)
			{
				_arena.Clear();
				instance.FindCharactersInRange(Center, 256f, ref _arena);
				_manager = instance;
				_frame = Time.frameCount;
			}
			return _arena;
		}

		internal void Reset()
		{
			_frame = -1;
			_manager = null;
			_arena.Clear();
			_fallback.Clear();
		}
	}
	[BepInPlugin("codex.outward.arena.torretas", "Codex - Oito Torretas da Arena", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Slot
		{
			internal TurretSpec Spec;

			internal SL_Character Template;

			internal Character Body;

			internal GameObject Field;

			internal bool Creating;

			internal bool Visited;

			internal int Generation;

			internal float NextAttempt;

			internal float NextWarning;

			internal Vector3 Position => new Vector3(1783f + Spec.X, 255f, 1796.7f + Spec.Z);
		}

		public const string Guid = "codex.outward.arena.torretas";

		internal const string Uid = "codex.character.arena.torreta";

		internal static Plugin Instance;

		private ConfigEntry<KeyboardShortcut> _reset;

		private ConfigEntry<bool> _detailed;

		private static readonly ArenaPlayerCandidates Candidates = new ArenaPlayerCandidates();

		private Slot[] _slots;

		internal bool Detailed
		{
			get
			{
				if (_detailed != null)
				{
					return _detailed.Value;
				}
				return false;
			}
		}

		internal static bool CombatSceneReady
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)CharacterManager.Instance != (Object)null && !PhotonNetwork.isNonMasterClientInRoom)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					return ((Scene)(ref activeScene)).name == "CierzoTutorial";
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_detailed = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostico", "Detalhado", false, "Registra cada disparo/acerto; desligado reduz escrita de log. Spawn,destruicao e erros sempre registrados.");
			_slots = new Slot[ArenaCatalog.All.Length];
			for (int i = 0; i < _slots.Length; i++)
			{
				_slots[i] = new Slot
				{
					Spec = ArenaCatalog.All[i]
				};
			}
			_reset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Teste", "Recriar", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Recria apenas a torreta mais proxima (ate15m), sem alterar as outras.");
			SL.OnPacksLoaded += PrepareTemplates;
			SceneManager.sceneLoaded += SceneLoaded;
			if (SL.PacksLoaded)
			{
				PrepareTemplates();
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[ArenaTorretas] 1.1.0: feixes NonAlloc com fallback seguro,busca compartilhada por frame,oito torretas,quatro por lateral;alcance50m. F10 recria a mais proxima ate15m.");
		}

		private void PrepareTemplates()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_0095: 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_00ad: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			Slot[] slots = _slots;
			foreach (Slot slot in slots)
			{
				if (slot.Template == null)
				{
					TurretSpec spec = slot.Spec;
					SL_Character val = new SL_Character
					{
						UID = "codex.character.arena.torreta." + spec.Id,
						Name = spec.Name,
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						DestroyOnDeath = false,
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						Faction = (Factions)9,
						CharacterVisualsData = new VisualData(),
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = -1,
						Boots_ID = -1,
						Backpack_ID = -1,
						Health = spec.Health,
						HealthRegen = 0f,
						Protection = 0f,
						Barrier = 0f,
						ImpactResist = 100f,
						Damage_Resists = new float[9],
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false
					};
					((ContentTemplate)val).ApplyTemplate();
					slot.Template = val;
					string name = spec.Name;
					string uID = val.UID;
					float health = spec.Health;
					Message(name, "Template temporario registrado: " + uID + "; vida=" + health);
				}
			}
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				((MonoBehaviour)this).StopAllCoroutines();
				Candidates.Reset();
				Slot[] slots = _slots;
				foreach (Slot slot in slots)
				{
					Cleanup(slot);
					slot.Visited = false;
					slot.NextAttempt = 0f;
				}
			}
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0064: 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_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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "CierzoTutorial" || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = _reset.Value;
			Slot[] slots;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Slot slot = null;
				float num = 225f;
				slots = _slots;
				foreach (Slot slot2 in slots)
				{
					Character val = NearestPlayer(slot2.Position, 15f);
					if (!((Object)(object)val == (Object)null) && (!((Object)(object)val.CharacterUI != (Object)null) || !val.CharacterUI.IsMenuFocused))
					{
						Vector3 val2 = val.CenterPosition - slot2.Position;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							slot = slot2;
							num = sqrMagnitude;
						}
					}
				}
				if (slot != null && !slot.Creating)
				{
					Message(slot.Spec.Name, "Recriacao solicitada por F10.");
					Cleanup(slot);
					slot.Visited = false;
					slot.NextAttempt = 0f;
				}
			}
			slots = _slots;
			for (int i = 0; i < slots.Length; i++)
			{
				if (slots[i].Creating)
				{
					return;
				}
			}
			slots = _slots;
			foreach (Slot slot3 in slots)
			{
				if (slot3.Template != null && !slot3.Visited && Time.realtimeSinceStartup >= slot3.NextAttempt && (Object)(object)NearestPlayer(slot3.Position, 150f) != (Object)null)
				{
					((MonoBehaviour)this).StartCoroutine(Create(slot3, slot3.Generation));
					break;
				}
			}
		}

		private unsafe IEnumerator Create(Slot slot, int generation)
		{
			slot.Creating = true;
			if (!ArenaPlacement.TrySurface(slot.Position, out var surface, out var support, out var reason) || !ArenaPlacement.SpotClear(surface, support, out reason))
			{
				if (Time.realtimeSinceStartup >= slot.NextWarning)
				{
					Plugin plugin = this;
					string name = slot.Spec.Name;
					string[] obj = new string[6] { "Aguardando em local(", null, null, null, null, null };
					float x = slot.Spec.X;
					obj[1] = x.ToString();
					obj[2] = ",";
					x = slot.Spec.Z;
					obj[3] = x.ToString();
					obj[4] = "): ";
					obj[5] = reason;
					plugin.Message(name, string.Concat(obj));
					slot.NextWarning = Time.realtimeSinceStartup + 15f;
				}
				slot.NextAttempt = Time.realtimeSinceStartup + 2f;
				slot.Creating = false;
				yield break;
			}
			try
			{
				slot.Body = slot.Template.Spawn(surface + Vector3.up * 0.08f, (string)null, (string)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[Torreta:" + slot.Spec.Name + "] Spawn: " + ex));
			}
			if ((Object)(object)slot.Body == (Object)null)
			{
				slot.NextAttempt = Time.realtimeSinceStartup + 5f;
				slot.Creating = false;
				yield break;
			}
			((Component)slot.Body).gameObject.AddComponent<HiddenDamageReceiver>();
			float deadline = Time.realtimeSinceStartup + 25f;
			while (generation == slot.Generation && (Object)(object)slot.Body != (Object)null && ((Object)(object)slot.Body.Stats == (Object)null || (Object)(object)slot.Body.Animator == (Object)null || slot.Body.Hitboxes == null || slot.Body.Hitboxes.Length == 0) && !(Time.realtimeSinceStartup > deadline))
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (generation != slot.Generation || (Object)(object)slot.Body == (Object)null)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)slot.Body.Stats == (Object)null || (Object)(object)slot.Body.Animator == (Object)null || slot.Body.Hitboxes == null || slot.Body.Hitboxes.Length == 0)
				{
					throw new InvalidOperationException("Receptor nativo ainda nao inicializou visual/hitboxes.");
				}
				slot.Body.Teleport(surface + Vector3.up * 0.08f, Quaternion.identity);
				slot.Body.Invincible = false;
				slot.Body.QuestInvicibility = false;
				slot.Body.QuestNonTargetable = false;
				slot.Body.Stats.SetHealth(slot.Spec.Health);
				slot.Field = new GameObject("Codex_Arena_Torreta_" + slot.Spec.Id);
				slot.Field.transform.position = surface;
				slot.Field.transform.localScale = Vector3.one * slot.Spec.Scale;
				TurretVisual turretVisual = slot.Field.AddComponent<TurretVisual>();
				turretVisual.Build(((Component)support).gameObject.layer, slot.Spec);
				int num = 0;
				for (int i = 0; i < 8; i++)
				{
					float num2 = (float)i * (float)Math.PI * 0.25f;
					if (TrySurface(surface + new Vector3(Mathf.Sin(num2) * 3f, 0f, Mathf.Cos(num2) * 3f), out var surface2))
					{
						turretVisual.AddMarker(slot.Field.transform.InverseTransformPoint(surface2), i);
						num++;
					}
				}
				((Component)slot.Body).gameObject.AddComponent<TurretController>().Initialize(slot.Body, turretVisual, surface, slot.Spec);
				slot.Visited = true;
				Plugin plugin2 = this;
				string name2 = slot.Spec.Name;
				string[] obj2 = new string[13]
				{
					"PRONTA em ", null, null, null, null, null, null, null, null, null,
					null, null, null
				};
				Vector3 val = surface;
				obj2[1] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				obj2[2] = "; apoio=";
				obj2[3] = ((Object)support).name;
				obj2[4] = "; camada=";
				obj2[5] = LayerMask.LayerToName(((Component)support).gameObject.layer);
				obj2[6] = "; marcos=";
				obj2[7] = num.ToString();
				obj2[8] = "; vida=";
				obj2[9] = slot.Body.Stats.CurrentHealth.ToString();
				obj2[10] = "; alcance=";
				float x = slot.Spec.Range;
				obj2[11] = x.ToString();
				obj2[12] = "m.";
				plugin2.Message(name2, string.Concat(obj2));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[Torreta:" + slot.Spec.Name + "] Setup sera repetido: " + ex2));
				Cleanup(slot);
				slot.NextAttempt = Time.realtimeSinceStartup + 5f;
			}
			slot.Creating = false;
		}

		internal static Character NearestPlayer(Vector3 point, float radius, bool combatOnly = false)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)CharacterManager.Instance == (Object)null)
			{
				return null;
			}
			List<Character> list = Candidates.Query(point, radius);
			Character result = null;
			float num = radius * radius;
			foreach (Character item in list)
			{
				if (!((Object)(object)item == (Object)null) && item.IsLocalPlayer && item.Alive && !(((Component)item).transform.position.y < 200f) && (!combatOnly || AllowsTarget(item)))
				{
					Vector3 val = item.CenterPosition - point;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = item;
					}
				}
			}
			return result;
		}

		internal static bool TrySurface(Vector3 position, out Vector3 surface)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Collider support;
			return TrySurface(position, out surface, out support);
		}

		private static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ArenaPlacement.TrySurface(position, out surface, out support);
		}

		internal static bool AllowsTarget(Character character)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || !CombatSceneReady)
			{
				return false;
			}
			Vector3 position = ((Component)character).transform.position;
			return ArenaCatalog.IsCombatPosition(position.x, position.y, position.z);
		}

		internal void Message(string name, string message)
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[ArenaTorretas:" + name + "] " + message));
		}

		private void Cleanup(Slot slot)
		{
			slot.Generation++;
			if ((Object)(object)slot.Body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(slot.Body);
			}
			if ((Object)(object)slot.Field != (Object)null)
			{
				Object.Destroy((Object)(object)slot.Field);
			}
			slot.Body = null;
			slot.Field = null;
			slot.Creating = false;
		}

		private void OnDestroy()
		{
			((MonoBehaviour)this).StopAllCoroutines();
			Candidates.Reset();
			SL.OnPacksLoaded -= PrepareTemplates;
			SceneManager.sceneLoaded -= SceneLoaded;
			if (_slots != null)
			{
				Slot[] slots = _slots;
				foreach (Slot slot in slots)
				{
					Cleanup(slot);
					if (slot.Template != null)
					{
						slot.Template.Unregister();
					}
				}
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	internal sealed class HiddenDamageReceiver : MonoBehaviour
	{
		private readonly List<Renderer> _renderers = new List<Renderer>();

		private float _nextRefresh;

		private void LateUpdate()
		{
			if (Time.time >= _nextRefresh)
			{
				((Component)this).GetComponentsInChildren<Renderer>(true, _renderers);
				_nextRefresh = Time.time + 0.1f;
			}
			foreach (Renderer renderer in _renderers)
			{
				if ((Object)(object)renderer != (Object)null && renderer.enabled)
				{
					renderer.enabled = false;
				}
			}
		}
	}
	internal sealed class TurretController : MonoBehaviour
	{
		private Character _body;

		private TurretVisual _visual;

		private Vector3 _anchor;

		private Vector3 _direction;

		private BeamCycle _cycle;

		private TurretSpec _spec;

		private StatusEffect _status;

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

		private List<Character> _targets = new List<Character>();

		private bool _ready;

		private bool _broken;

		private BeamPhase _previous;

		private float _nextVisibility;

		private readonly RaycastHit[] _beamHits = (RaycastHit[])(object)new RaycastHit[32];

		private Collider[] _brokenColliders;

		internal void Initialize(Character body, TurretVisual visual, Vector3 floor, TurretSpec spec)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_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_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			_spec = spec;
			_cycle = new BeamCycle(spec.Warning, spec.Fire, spec.Cooldown);
			if (spec.Status != null)
			{
				_status = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(spec.Status);
				Plugin.Instance.Message(spec.Name, ((Object)(object)_status != (Object)null) ? ("Status nativo encontrado: " + _status.IdentifierName) : ("AVISO: status nativo ausente: " + spec.Status + "; dano elemental permanece, status nao aplicado."));
			}
			_body = body;
			_visual = visual;
			_anchor = floor + Vector3.up * 0.08f;
			CharacterAI component = ((Component)body).GetComponent<CharacterAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			NavMeshAgent component2 = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			CharacterControl component3 = ((Component)body).GetComponent<CharacterControl>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			if ((Object)(object)body.CharacterController != (Object)null)
			{
				((Collider)body.CharacterController).enabled = false;
			}
			Hitbox[] componentsInChildren = ((Component)body).GetComponentsInChildren<Hitbox>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Collider[] components = ((Component)componentsInChildren[i]).GetComponents<Collider>();
				for (int j = 0; j < components.Length; j++)
				{
					components[j].enabled = false;
				}
			}
			GameObject val = new GameObject("Torreta_Receptor_Nativo_" + spec.Id);
			val.transform.SetParent(((Component)body).transform, false);
			val.layer = LayerMask.NameToLayer("Hitbox");
			if (val.layer < 0)
			{
				throw new InvalidOperationException("Camada Hitbox nativa nao encontrada.");
			}
			CapsuleCollider obj = val.AddComponent<CapsuleCollider>();
			obj.radius = 0.66f * spec.Scale;
			obj.height = 1.78f * spec.Scale;
			obj.center = Vector3.up * 0.84f * spec.Scale;
			((Collider)obj).isTrigger = true;
			Hitbox val2 = val.AddComponent<Hitbox>();
			val2.OwnerChar = body;
			val2.Melee = true;
			val2.Ranged = true;
			FieldInfo? field = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("Character.m_hitboxes");
			}
			field.SetValue(body, new Hitbox[1] { val2 });
			body.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(OnBroken));
			_ready = true;
		}

		private void Update()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: 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_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: 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_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: 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_041b: 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_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: 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_043c: 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)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Expected O, but got Unknown
			if (!_ready || (Object)(object)_body == (Object)null || (Object)(object)_visual == (Object)null)
			{
				return;
			}
			if (!Plugin.CombatSceneReady)
			{
				_visual.HideBeam();
				return;
			}
			if (!_body.Alive)
			{
				OnBroken();
			}
			if (Time.time >= _nextVisibility)
			{
				_visual.SetVisible((Object)(object)Plugin.NearestPlayer(_anchor, 150f) != (Object)null);
				_nextVisibility = Time.time + 0.25f;
			}
			if (_broken)
			{
				return;
			}
			Character val = Plugin.NearestPlayer(_visual.Muzzle, _spec.Range, combatOnly: true);
			bool targetVisible = false;
			if ((Object)(object)val != (Object)null)
			{
				Vector3 val2 = val.CenterPosition - _visual.Muzzle;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				targetVisible = ClipBeam(_visual.Muzzle, normalized, Vector3.Distance(_visual.Muzzle, val.CenterPosition)) >= Vector3.Distance(_visual.Muzzle, val.CenterPosition) - 0.03f;
				if (_cycle.Phase != BeamPhase.Firing)
				{
					_visual.Head.rotation = Quaternion.RotateTowards(_visual.Head.rotation, Quaternion.LookRotation(normalized), 180f * Time.deltaTime);
				}
				targetVisible = targetVisible && Vector3.Angle(_visual.Head.forward, normalized) < 8f;
			}
			BeamPhase beamPhase = _cycle.Step(Time.time, _body.Alive, targetVisible);
			if (beamPhase != _previous)
			{
				if (beamPhase == BeamPhase.Warning)
				{
					_visual.SetCharge(value: true);
				}
				if (beamPhase == BeamPhase.Firing)
				{
					_direction = _visual.Head.forward;
					_hit.Clear();
					if (Plugin.Instance.Detailed)
					{
						Plugin instance = Plugin.Instance;
						string name = _spec.Name;
						string[] obj = new string[7] { "Disparo: ", null, null, null, null, null, null };
						float damage = _spec.Damage;
						obj[1] = damage.ToString();
						obj[2] = " ";
						obj[3] = _spec.Element.ToString();
						obj[4] = "/";
						damage = _spec.Impact;
						obj[5] = damage.ToString();
						obj[6] = " impacto; um acerto por alvo neste feixe.";
						instance.Message(name, string.Concat(obj));
					}
				}
				if (beamPhase == BeamPhase.Idle || beamPhase == BeamPhase.Cooldown)
				{
					_visual.SetCharge(value: false);
					_visual.HideBeam();
				}
				_previous = beamPhase;
			}
			if (beamPhase != BeamPhase.Firing)
			{
				return;
			}
			Vector3 muzzle = _visual.Muzzle;
			float num = ClipBeam(muzzle, _direction, _spec.Range);
			_visual.ShowBeam(muzzle, muzzle + _direction * num);
			_targets.Clear();
			CharacterManager.Instance.FindCharactersInRange(muzzle, _spec.Range + 1f, ref _targets);
			foreach (Character target in _targets)
			{
				if ((Object)(object)target == (Object)null || !target.IsLocalPlayer || !target.Alive || _hit.Contains(target) || !Plugin.AllowsTarget(target))
				{
					continue;
				}
				Vector3 val3 = target.CenterPosition - muzzle;
				float num2 = Vector3.Dot(val3, _direction);
				if (num2 < 0f || num2 > num || BeamCycle.DistanceToSegmentSquared(val3.x, val3.y, val3.z, _direction.x, _direction.y, _direction.z, num) > 0.3025f)
				{
					continue;
				}
				Vector3 val4 = muzzle + _direction * num2;
				Vector3 val5 = target.CenterPosition - val4;
				if (((Vector3)(ref val5)).sqrMagnitude > 0.001f && ClipBeam(val4, ((Vector3)(ref val5)).normalized, ((Vector3)(ref val5)).magnitude) < ((Vector3)(ref val5)).magnitude - 0.01f)
				{
					continue;
				}
				_hit.Add(target);
				Types val6 = (Types)((_spec.Element == TurretElement.Decay) ? 2 : ((_spec.Element == TurretElement.Fire) ? 5 : ((_spec.Element == TurretElement.Frost) ? 4 : 3)));
				target.ReceiveHit((Object)null, new DamageList(val6, _spec.Damage), _direction, target.CenterPosition, 45f, 1f, _body, _spec.Impact, true);
				if ((Object)(object)_status != (Object)null && target.Alive && (Object)(object)target.StatusEffectMngr != (Object)null)
				{
					target.StatusEffectMngr.AddStatusEffectBuildUp(_status, _spec.Buildup, _body);
				}
				if (Plugin.Instance.Detailed)
				{
					Plugin instance2 = Plugin.Instance;
					string name2 = _spec.Name;
					string name3 = target.Name;
					object obj3;
					if (!((Object)(object)_status == (Object)null))
					{
						string[] obj2 = new string[5] { "; acumulo nativo ", _spec.Status, "=", null, null };
						float damage = _spec.Buildup;
						obj2[3] = damage.ToString();
						obj2[4] = "%.";
						obj3 = string.Concat(obj2);
					}
					else
					{
						obj3 = ".";
					}
					instance2.Message(name2, "Acerto confirmado em " + name3 + (string?)obj3);
				}
			}
		}

		private float ClipBeam(Vector3 start, Vector3 direction, float length)
		{
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.RaycastNonAlloc(start, direction, _beamHits, length, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			RaycastHit[] array = _beamHits;
			if (num == _beamHits.Length)
			{
				array = Physics.RaycastAll(start, direction, length, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				num = array.Length;
			}
			for (int i = 0; i < num; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)this).transform) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)_visual).transform))
				{
					length = Mathf.Min(length, ((RaycastHit)(ref val)).distance);
				}
			}
			return length;
		}

		private void OnBroken()
		{
			if (!_broken)
			{
				_broken = true;
				_cycle.Step(Time.time, alive: false, targetVisible: false);
				_visual.Break();
				_brokenColliders = ((Component)this).GetComponentsInChildren<Collider>(true);
				Plugin.Instance.Message(_spec.Name, "DESATIVADA por dano nativo; vida=" + _body.Stats.CurrentHealth + ". Carcaca mantida; F10 perto dela recria somente esta.");
			}
		}

		private void LateUpdate()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!_ready || (Object)(object)_body == (Object)null)
			{
				return;
			}
			((Component)this).transform.position = _anchor;
			if (!_broken)
			{
				return;
			}
			Collider[] brokenColliders = _brokenColliders;
			foreach (Collider val in brokenColliders)
			{
				if ((Object)(object)val != (Object)null && val.enabled)
				{
					val.enabled = false;
				}
			}
		}

		private void OnDestroy()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)_body != (Object)null)
			{
				Character body = _body;
				body.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(OnBroken));
			}
			if ((Object)(object)_visual != (Object)null)
			{
				_visual.HideBeam();
			}
		}
	}
	public enum TurretElement
	{
		Electric,
		Decay,
		Fire,
		Frost
	}
	public enum TurretShape
	{
		Original,
		Viper,
		Emerald,
		Ember,
		Aurora
	}
	public sealed class TurretSpec
	{
		public readonly string Id;

		public readonly string Name;

		public readonly string Status;

		public readonly float X;

		public readonly float Z;

		public readonly float Health;

		public readonly float Range;

		public readonly float Damage;

		public readonly float Impact;

		public readonly float Warning;

		public readonly float Fire;

		public readonly float Cooldown;

		public readonly float Buildup;

		public readonly float Scale;

		public readonly float Red;

		public readonly float Green;

		public readonly float Blue;

		public readonly TurretElement Element;

		public readonly TurretShape Shape;

		public TurretSpec(string id, string name, float x, float z, float health, float range, float damage, float impact, float warning, float fire, float cooldown, TurretElement element, string status, float buildup, TurretShape shape, float scale, float red, float green, float blue)
		{
			Id = id;
			Name = name;
			X = x;
			Z = z;
			Health = health;
			Range = range;
			Damage = damage;
			Impact = impact;
			Warning = warning;
			Fire = fire;
			Cooldown = cooldown;
			Element = element;
			Status = status;
			Buildup = buildup;
			Shape = shape;
			Scale = scale;
			Red = red;
			Green = green;
			Blue = blue;
		}
	}
	public static class TurretCatalog
	{
		public static readonly TurretSpec[] All = new TurretSpec[5]
		{
			new TurretSpec("azul", "Sentinela Runica de Treino", -18f, -40f, 1f, 12f, 12f, 8f, 1.1f, 0.45f, 3.2f, TurretElement.Electric, null, 0f, TurretShape.Original, 1f, 0.15f, 0.65f, 1f),
			new TurretSpec("vibora", "Vibora", 18f, -44f, 24f, 8f, 6f, 0f, 0.25f, 0.16f, 0.55f, TurretElement.Decay, "Poisoned", 35f, TurretShape.Viper, 1.1f, 0.38f, 1f, 0.08f),
			new TurretSpec("esmeralda", "Esmeralda", 46f, -9f, 32f, 16f, 8f, 0f, 0.55f, 0.22f, 1.1f, TurretElement.Decay, "Poisoned", 100f, TurretShape.Emerald, 1.15f, 0.04f, 0.86f, 0.34f),
			new TurretSpec("brasa", "Brasa", -46f, 8f, 45f, 18f, 14f, 6f, 0.8f, 0.35f, 2.2f, TurretElement.Fire, "Burning", 100f, TurretShape.Ember, 1.2f, 1f, 0.12f, 0.04f),
			new TurretSpec("aurora", "Aurora", 22f, 39f, 60f, 28f, 22f, 14f, 1.4f, 0.45f, 4.2f, TurretElement.Frost, null, 0f, TurretShape.Aurora, 1.35f, 0.8f, 0.94f, 1f)
		};
	}
	public sealed class TurretVisual : MonoBehaviour
	{
		private TurretSpec _spec;

		private Color _tint;

		private float _muzzleZ = 0.77f;

		private readonly List<Object> _owned = new List<Object>();

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

		private readonly List<LineRenderer> _beam = new List<LineRenderer>();

		private Material _stone;

		private Material _metal;

		private Material _gold;

		private Material _glow;

		private Light _light;

		private ParticleSystem _smoke;

		private bool _visible = true;

		private bool _broken;

		public Transform Head { get; private set; }

		public Vector3 Muzzle => Head.TransformPoint(new Vector3(0f, 0f, _muzzleZ));

		public void Build(int groundLayer = -1, TurretSpec spec = null)
		{
			//IL_0034: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Expected O, but got Unknown
			//IL_0367: 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_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: 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_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Expected O, but got Unknown
			//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ff: 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_07c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b8: Expected O, but got Unknown
			//IL_0723: 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_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: 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_0737: 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_06d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_075e: Unknown result type (might be due to invalid IL or missing references)
			_spec = spec ?? TurretCatalog.All[0];
			_tint = new Color(_spec.Red, _spec.Green, _spec.Blue);
			bool flag = _spec.Shape == TurretShape.Original;
			bool flag2 = _spec.Shape == TurretShape.Aurora;
			_muzzleZ = (flag2 ? 1.28f : 0.77f);
			_stone = Finish("Pedra_Runic", new Color(0.29f, 0.34f, 0.38f), 0.04f, 0.2f);
			_metal = Finish("Metal_Runic", new Color(0.13f, 0.18f, 0.22f), 0.7f, 0.62f);
			_gold = Finish("Aros_Gravados", new Color(0.47f, 0.37f, 0.2f), 0.68f, 0.5f);
			_glow = Finish("Cristal_" + _spec.Id, (Color)(flag ? new Color(0.12f, 0.56f, 0.75f) : _tint), 0.3f, 0.7f);
			_glow.EnableKeyword("_EMISSION");
			_glow.SetColor("_EmissionColor", (Color)(flag ? new Color(0.06f, 0.25f, 0.38f) : (_tint * 0.4f)));
			Lathe("Base_Pedra", ((Component)this).transform, new float[4] { 0f, 0.07f, 0.18f, 0.23f }, new float[4] { 0.76f, 0.8f, 0.72f, 0.56f }, _stone);
			Lathe("Pilar", ((Component)this).transform, new float[6] { 0.18f, 0.27f, 0.36f, 0.95f, 1.1f, 1.2f }, new float[6] { 0.5f, 0.52f, 0.39f, 0.25f, 0.4f, 0.4f }, _stone);
			Lathe("Aro_Inferior", ((Component)this).transform, new float[4] { 0.25f, 0.28f, 0.32f, 0.35f }, new float[4] { 0.5f, 0.55f, 0.55f, 0.46f }, _gold);
			Lathe("Aro_Superior", ((Component)this).transform, new float[4] { 0.98f, 1.02f, 1.07f, 1.1f }, new float[4] { 0.31f, 0.43f, 0.43f, 0.39f }, _gold);
			for (int i = 0; i < 6; i++)
			{
				GameObject obj = Lathe("Runa_" + i, ((Component)this).transform, new float[2] { 0f, 0.34f }, new float[2] { 0.021f, 0.015f }, _glow);
				float num = (float)i * (float)Math.PI / 3f;
				obj.transform.localPosition = new Vector3(Mathf.Sin(num) * 0.335f, 0.51f, Mathf.Cos(num) * 0.335f);
				obj.transform.localRotation = Quaternion.Euler(0f, (float)i * 60f, 12f);
			}
			GameObject val = new GameObject("Cabeca_Giratoria");
			val.transform.SetParent(((Component)this).transform, false);
			Head = val.transform;
			Head.localPosition = Vector3.up * 1.4f;
			Lathe("Cabeca_Metal", Head, new float[5] { -0.21f, -0.12f, 0.06f, 0.16f, 0.23f }, new float[5] { 0.28f, 0.38f, 0.42f, 0.36f, 0.25f }, _metal).transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			for (int j = 0; j < 3; j++)
			{
				GameObject obj2 = Lathe("Anel_Canhao_" + j, Head, new float[3] { 0f, 0.05f, 0.1f }, new float[3]
				{
					0.23f - (float)j * 0.03f,
					0.26f - (float)j * 0.03f,
					0.23f - (float)j * 0.03f
				}, _gold);
				obj2.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				obj2.transform.localPosition = Vector3.forward * (0.19f + (float)j * 0.16f);
			}
			GameObject obj3 = Lathe("Canhao", Head, (!flag2) ? new float[4] { 0f, 0.12f, 0.42f, 0.58f } : new float[4] { 0f, 0.12f, 0.9f, 1.08f }, new float[4] { 0.18f, 0.18f, 0.13f, 0.16f }, _metal);
			obj3.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			obj3.transform.localPosition = Vector3.forward * 0.15f;
			GameObject obj4 = Lathe("Olho_Cristal", Head, new float[3] { 0f, 0.04f, 0.13f }, new float[3] { 0.13f, 0.14f, 0f }, _glow);
			obj4.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			obj4.transform.localPosition = Vector3.forward * (_muzzleZ - 0.06f);
			AddModelDetails();
			GameObject val2 = new GameObject("Luz_Aviso");
			val2.transform.SetParent(Head, false);
			val2.transform.localPosition = Vector3.forward * (_muzzleZ + 0.05f);
			_light = val2.AddComponent<Light>();
			_light.color = _tint;
			_light.range = 3f;
			_light.intensity = 0.8f;
			_light.shadows = (LightShadows)0;
			for (int k = 0; k < 3; k++)
			{
				GameObject val3 = new GameObject("Feixe_" + k);
				val3.transform.SetParent(((Component)this).transform, false);
				LineRenderer val4 = val3.AddComponent<LineRenderer>();
				val4.useWorldSpace = true;
				val4.positionCount = 2;
				val4.widthMultiplier = k switch
				{
					1 => 0.06f, 
					0 => 0.16f, 
					_ => 0.018f, 
				};
				val4.numCapVertices = 6;
				Material val5 = new Material(Shader.Find("Sprites/Default"));
				_owned.Add((Object)(object)val5);
				if (flag)
				{
					val5.color = (Color)(k switch
					{
						1 => new Color(0.18f, 0.82f, 1f, 0.8f), 
						0 => new Color(0.06f, 0.46f, 0.9f, 0.25f), 
						_ => Color.white, 
					});
				}
				else
				{
					Color color = ((k == 2) ? Color.Lerp(_tint, Color.white, 0.28f) : _tint);
					color.a = k switch
					{
						1 => 0.8f, 
						0 => 0.25f, 
						_ => 1f, 
					};
					val5.color = color;
				}
				((Renderer)val4).sharedMaterial = val5;
				((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val4).receiveShadows = false;
				_beam.Add(val4);
				((Renderer)val4).enabled = false;
			}
			CapsuleCollider obj5 = ((Component)this).gameObject.AddComponent<CapsuleCollider>();
			obj5.radius = 0.48f;
			obj5.height = 1.32f;
			obj5.center = Vector3.up * 0.66f;
			((Component)this).gameObject.layer = ((groundLayer >= 0) ? groundLayer : LayerMask.NameToLayer("Default"));
		}

		public void AddMarker(Vector3 position, int index)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Lathe("Marco_Campo_" + index, ((Component)this).transform, new float[3] { 0f, 0.045f, 0.11f }, new float[3] { 0.25f, 0.32f, 0.18f }, _stone);
			obj.transform.localPosition = position;
			obj.transform.localScale = Vector3.one / _spec.Scale;
		}

		public void SetCharge(bool value)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Color val = (Color)((_spec.Shape != TurretShape.Original) ? (_tint * (value ? 1.8f : 0.4f)) : (value ? new Color(0.1f, 1.1f, 1.8f) : new Color(0.06f, 0.25f, 0.38f)));
			_glow.SetColor("_EmissionColor", _broken ? Color.black : val);
			if ((Object)(object)_light != (Object)null)
			{
				_light.intensity = (value ? 2.2f : 0.8f);
			}
		}

		public void ShowBeam(Vector3 start, Vector3 end)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			foreach (LineRenderer item in _beam)
			{
				item.SetPosition(0, start);
				item.SetPosition(1, end);
				((Renderer)item).enabled = _visible && !_broken;
			}
		}

		public void HideBeam()
		{
			foreach (LineRenderer item in _beam)
			{
				if ((Object)(object)item != (Object)null)
				{
					((Renderer)item).enabled = false;
				}
			}
		}

		public void SetVisible(bool visible)
		{
			_visible = visible;
			foreach (Renderer renderer in _renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = visible;
				}
			}
			if ((Object)(object)_light != (Object)null)
			{
				((Behaviour)_light).enabled = visible && !_broken;
			}
			if (!visible)
			{
				HideBeam();
			}
			if ((Object)(object)_smoke != (Object)null)
			{
				((Renderer)((Component)_smoke).GetComponent<ParticleSystemRenderer>()).enabled = visible;
			}
		}

		public void Break()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!_broken)
			{
				_broken = true;
				HideBeam();
				SetCharge(value: false);
				((Behaviour)_light).enabled = false;
				_glow.color = new Color(0.07f, 0.1f, 0.12f);
				Smoke();
			}
		}

		private void AddModelDetails()
		{
			//IL_0274: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_0622: Unknown result type (might be due to invalid IL or missing references)
			if (_spec.Shape == TurretShape.Viper)
			{
				for (int i = -1; i <= 1; i += 2)
				{
					Vector3[] array = (Vector3[])(object)new Vector3[16];
					for (int j = 0; j < array.Length; j++)
					{
						float num = (float)j / (float)(array.Length - 1);
						float num2 = num * (float)Math.PI * 2f;
						array[j] = new Vector3((float)i * (0.34f + 0.1f * Mathf.Sin(num2)), 0.38f + num * 0.9f, 0.12f * Mathf.Cos(num2));
					}
					Tube("Serpente_" + i, ((Component)this).transform, array, 0.065f, _gold);
					GameObject obj = Lathe("Presa_" + i, Head, new float[3] { 0f, 0.18f, 0.25f }, new float[3] { 0.055f, 0.035f, 0f }, _gold);
					obj.transform.localPosition = new Vector3((float)i * 0.22f, -0.05f, 0.62f);
					obj.transform.localRotation = Quaternion.Euler(180f, 0f, (float)(-i * 14));
					GameObject obj2 = Lathe("Olho_Serpente_" + i, Head, new float[3] { 0f, 0.04f, 0.08f }, new float[3] { 0.06f, 0.07f, 0f }, _glow);
					obj2.transform.localPosition = new Vector3((float)i * 0.25f, 0.13f, 0.24f);
					obj2.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				}
			}
			else if (_spec.Shape == TurretShape.Emerald)
			{
				for (int k = 0; k < 3; k++)
				{
					float num3 = (float)k * (float)Math.PI * 2f / 3f;
					GameObject val = Lathe("Reservatorio_Veneno_" + k, ((Component)this).transform, new float[6] { 0f, 0.06f, 0.12f, 0.52f, 0.58f, 0.64f }, new float[6] { 0.08f, 0.12f, 0.13f, 0.13f, 0.08f, 0.06f }, _glow);
					val.transform.localPosition = new Vector3(Mathf.Sin(num3) * 0.43f, 0.4f, Mathf.Cos(num3) * 0.43f);
					Lathe("Tampa_Frasco_" + k, val.transform, new float[3] { 0.58f, 0.62f, 0.67f }, new float[3] { 0.1f, 0.1f, 0.08f }, _gold);
					Lathe("Suporte_Frasco_" + k, val.transform, new float[3] { 0f, 0.04f, 0.1f }, new float[3] { 0.16f, 0.16f, 0.1f }, _metal);
				}
			}
			else if (_spec.Shape == TurretShape.Ember)
			{
				Lathe("Camara_Fornalha", ((Component)this).transform, new float[4] { 0.36f, 0.42f, 0.87f, 0.93f }, new float[4] { 0.36f, 0.37f, 0.37f, 0.32f }, _glow);
				for (int l = 0; l < 8; l++)
				{
					float num4 = (float)l * (float)Math.PI / 4f;
					Lathe("Grade_Fornalha_" + l, ((Component)this).transform, new float[2] { 0f, 0.57f }, new float[2] { 0.035f, 0.035f }, _metal).transform.localPosition = new Vector3(Mathf.Sin(num4) * 0.38f, 0.36f, Mathf.Cos(num4) * 0.38f);
				}
				for (int m = -1; m <= 1; m += 2)
				{
					GameObject val2 = Lathe("Chamine_" + m, Head, new float[3] { 0f, 0.16f, 0.28f }, new float[3] { 0.1f, 0.09f, 0.12f }, _metal);
					val2.transform.localPosition = new Vector3((float)m * 0.28f, 0.12f, -0.1f);
					Lathe("Brasa_Chamine_" + m, val2.transform, new float[2] { 0.26f, 0.28f }, new float[2] { 0.09f, 0.07f }, _glow);
				}
			}
			else if (_spec.Shape == TurretShape.Aurora)
			{
				for (int n = -1; n <= 1; n += 2)
				{
					GameObject obj3 = Lathe("Cristal_Gelo_" + n, Head, new float[3] { 0f, 0.09f, 0.46f }, new float[3] { 0.11f, 0.13f, 0f }, _glow);
					obj3.transform.localPosition = new Vector3((float)n * 0.35f, 0.05f, -0.04f);
					obj3.transform.localRotation = Quaternion.Euler(0f, 0f, (float)(-n * 25));
				}
				for (int num5 = 0; num5 < 2; num5++)
				{
					GameObject obj4 = Lathe("Anel_Longo_" + num5, Head, new float[3] { 0f, 0.04f, 0.08f }, new float[3] { 0.17f, 0.22f, 0.17f }, _gold);
					obj4.transform.localPosition = Vector3.forward * (0.8f + (float)num5 * 0.25f);
					obj4.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				}
			}
		}

		private void Tube(string name, Transform parent, Vector3[] path, float radius, Material material)
		{
			//IL_0029: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			for (int i = 0; i < path.Length; i++)
			{
				Vector3 val = path[Mathf.Min(i + 1, path.Length - 1)] - path[Mathf.Max(0, i - 1)];
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				val = Vector3.Cross(normalized, Vector3.forward);
				Vector3 normalized2 = ((Vector3)(ref val)).normalized;
				val = Vector3.Cross(normalized2, normalized);
				Vector3 normalized3 = ((Vector3)(ref val)).normalized;
				for (int j = 0; j <= 12; j++)
				{
					float num = (float)j * (float)Math.PI * 2f / 12f;
					list.Add(path[i] + (normalized2 * Mathf.Cos(num) + normalized3 * Mathf.Sin(num)) * radius);
					list2.Add(new Vector2((float)j / 12f, (float)i / (float)(path.Length - 1)));
				}
			}
			for (int k = 0; k < path.Length - 1; k++)
			{
				for (int l = 0; l < 12; l++)
				{
					int num2 = k * 13 + l;
					int num3 = num2 + 1;
					int num4 = num2 + 12 + 1;
					int num5 = num4 + 1;
					list3.AddRange(new int[6] { num2, num4, num3, num3, num4, num5 });
				}
			}
			for (int m = 0; m < 2; m++)
			{
				int num6 = ((m != 0) ? (path.Length - 1) : 0);
				int count = list.Count;
				list.Add(path[num6]);
				list2.Add(new Vector2(0.5f, 0.5f));
				for (int n = 0; n < 12; n++)
				{
					int num7 = num6 * 13 + n;
					int num8 = num7 + 1;
					list3.AddRange((m == 0) ? new int[3] { count, num7, num8 } : new int[3] { count, num8, num7 });
				}
			}
			Mesh val2 = new Mesh();
			((Object)val2).name = name;
			val2.SetVertices(list);
			val2.SetUVs(0, list2);
			val2.SetTriangles(list3, 0);
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			_owned.Add((Object)(object)val2);
			GameObject val3 = new GameObject(name);
			val3.transform.SetParent(parent, false);
			val3.AddComponent<MeshFilter>().sharedMesh = val2;
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			((Renderer)val4).sharedMaterial = material;
			((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val4).receiveShadows = false;
			_renderers.Add((Renderer)(object)val4);
		}

		private Material Finish(string name, Color color, float metallic, float smoothness)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(Shader.Find("Standard"));
			((Object)val).name = name;
			val.color = color;
			val.SetFloat("_Metallic", metallic);
			val.SetFloat("_Glossiness", smoothness);
			Texture2D val2 = new Texture2D(128, 128, (TextureFormat)3, true);
			((Object)val2).name = name + "_Textura";
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = Mathf.PerlinNoise((float)j * 0.17f, (float)i * 0.17f) * 0.22f + Mathf.PerlinNoise((float)j * 0.045f, (float)i * 0.045f) * 0.2f;
					array[i * 128 + j] = Color.white * (0.66f + num);
				}
			}
			val2.SetPixels(array);
			val2.Apply(true, true);
			val.mainTexture = (Texture)(object)val2;
			_owned.Add((Object)(object)val2);
			_owned.Add((Object)(object)val);
			return val;
		}

		private GameObject Lathe(string name, Transform parent, float[] heights, float[] radii, Material material)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			for (int i = 0; i < heights.Length; i++)
			{
				for (int j = 0; j <= 24; j++)
				{
					float num = (float)j * (float)Math.PI * 2f / 24f;
					list.Add(new Vector3(Mathf.Sin(num) * radii[i], heights[i], Mathf.Cos(num) * radii[i]));
					list2.Add(new Vector2((float)j / 24f, heights[i] * 2f));
				}
			}
			for (int k = 0; k < heights.Length - 1; k++)
			{
				for (int l = 0; l < 24; l++)
				{
					int num2 = k * 25 + l;
					int num3 = num2 + 1;
					int num4 = num2 + 24 + 1;
					int num5 = num4 + 1;
					list3.AddRange(new int[6] { num2, num3, num4, num3, num5, num4 });
				}
			}
			for (int m = 0; m < 2; m++)
			{
				int num6 = ((m != 0) ? (heights.Length - 1) : 0);
				int count = list.Count;
				list.Add(Vector3.up * heights[num6]);
				list2.Add(new Vector2(0.5f, 0.5f));
				for (int n = 0; n < 24; n++)
				{
					int num7 = num6 * 25 + n;
					int num8 = num7 + 1;
					list3.AddRange((m == 0) ? new int[3] { count, num8, num7 } : new int[3] { count, num7, num8 });
				}
			}
			Mesh val = new Mesh();
			((Object)val).name = name;
			val.SetVertices(list);
			val.SetUVs(0, list2);
			val.SetTriangles(list3, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			_owned.Add((Object)(object)val);
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(parent, false);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
			((Renderer)val3).sharedMaterial = material;
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
			_renderers.Add((Renderer)(object)val3);
			return val2;
		}

		private void Smoke()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0023: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_0144: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01fa: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Fumaca_Carcaca");
			val.transform.SetParent(Head, false);
			val.transform.localPosition = Vector3.up * 0.18f;
			_smoke = val.AddComponent<ParticleSystem>();
			_smoke.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = _smoke.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).duration = 8f;
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(2f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.2f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.18f, 0.42f);
			((MainModule)(ref main)).maxParticles = 32;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			EmissionModule emission = _smoke.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(5f);
			ShapeModule shape = _smoke.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.08f;
			VelocityOverLifetimeModule velocityOverLifetime = _smoke.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = MinMaxCurve.op_Implicit(0.35f);
			Gradient val2 = new Gradient();
			val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(0.2f, 0.23f, 0.25f), 0f),
				new GradientColorKey(new Color(0.45f, 0.48f, 0.5f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(0.4f, 0.2f),
				new GradientAlphaKey(0f, 1f)
			});
			ColorOverLifetimeModule colorOverLifetime = _smoke.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
			Texture2D val3 = new Texture2D(32, 32, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[1024];
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(15.5f, 15.5f)) / 15.5f;
					array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - num), 2f));
				}
			}
			val3.SetPixels(array);
			val3.Apply(false, true);
			_owned.Add((Object)(object)val3);
			Material val4 = new Material(Shader.Find("Sprites/Default"));
			val4.mainTexture = (Texture)(object)val3;
			_owned.Add((Object)(object)val4);
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = val4;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			_smoke.Play(true);
		}

		private void OnDestroy()
		{
			foreach (Object item in _owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
		}
	}
	public enum BeamPhase
	{
		Idle,
		Warning,
		Firing,
		Cooldown,
		Broken
	}
	public sealed class BeamCycle
	{
		public const float Range = 12f;

		public const float WarningTime = 1.1f;

		public const float FireTime = 0.45f;

		public const float CooldownTime = 3.2f;

		private readonly float _warning;

		private readonly float _fire;

		private readonly float _cooldown;

		public BeamPhase Phase { get; private set; }

		public float Deadline { get; private set; }

		public BeamCycle(float warning = 1.1f, float fire = 0.45f, float cooldown = 3.2f)
		{
			if (warning <= 0f || fire <= 0f || cooldown <= 0f || float.IsNaN(warning + fire + cooldown) || float.IsInfinity(warning + fire + cooldown))
			{
				throw new ArgumentOutOfRangeException("Turret timing must be positive and finite.");
			}
			_warning = warning;
			_fire = fire;
			_cooldown = cooldown;
		}

		public BeamPhase Step(float time, bool alive, bool targetVisible)
		{
			if (!alive)
			{
				Phase = BeamPhase.Broken;
				return Phase;
			}
			if (Phase == BeamPhase.Broken)
			{
				return Phase;
			}
			if ((Phase == BeamPhase.Idle || Phase == BeamPhase.Warning) && !targetVisible)
			{
				Phase = BeamPhase.Idle;
				return Phase;
			}
			if (Phase == BeamPhase.Idle && targetVisible)
			{
				Phase = BeamPhase.Warning;
				Deadline = time + _warning;
			}
			else if (Phase == BeamPhase.Warning && time >= Deadline)
			{
				Phase = BeamPhase.Firing;
				Deadline = time + _fire;
			}
			else if (Phase == BeamPhase.Firing && time >= Deadline)
			{
				Phase = BeamPhase.Cooldown;
				Deadline = time + _cooldown;
			}
			else if (Phase == BeamPhase.Cooldown && time >= Deadline)
			{
				Phase = BeamPhase.Idle;
			}
			return Phase;
		}

		public static float DistanceToSegmentSquared(float x, float y, float z, float dx, float dy, float dz, float length)
		{
			float num = Math.Max(0f, Math.Min(length, x * dx + y * dy + z * dz));
			x -= num * dx;
			y -= num * dy;
			z -= num * dz;
			return x * x + y * y + z * z;
		}
	}
}

BepInEx/plugins/Codex_Chefe_Fornalha/CodexChefeFornalha.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using CodexCombat;
using CodexTorretaRunica;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexTorretaRunica
{
	internal static class ArenaPlacement
	{
		internal const string FloorName = "CampoMecanico_Arena_Piso";

		internal static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string reason;
			return TrySurface(position, out surface, out support, out reason);
		}

		internal unsafe static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support, out string reason)
		{
			//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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			surface = position;
			support = null;
			reason = null;
			GameObject val = GameObject.Find("CampoMecanico_Arena_Piso");
			Collider val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Collider>());
			if ((Object)(object)val2 == (Object)null)
			{
				reason = "Piso da arena ausente";
				return false;
			}
			if (!val2.enabled || !((Component)val2).gameObject.activeInHierarchy)
			{
				reason = "Piso da arena inativo";
				return false;
			}
			RaycastHit val3 = default(RaycastHit);
			if (!val2.Raycast(new Ray(new Vector3(position.x, 280f, position.z), Vector3.down), ref val3, 35f))
			{
				Vector3 val4 = position;
				reason = "Ray sem contato com piso da arena em " + ((object)(*(Vector3*)(&val4))/*cast due to .constrained prefix*/).ToString();
				return false;
			}
			if (((RaycastHit)(ref val3)).point.y <= 200f)
			{
				reason = "Piso abaixo da area elevada";
				return false;
			}
			int layer = ((Component)val2).gameObject.layer;
			if ((Global.GeneralEnvironmentMask & (1 << layer)) == 0)
			{
				reason = "Camada piso=" + layer + " fora da mascara ambiente=" + Global.GeneralEnvironmentMask;
				return false;
			}
			surface = ((RaycastHit)(ref val3)).point;
			support = val2;
			return true;
		}

		internal static bool SpotClear(Vector3 floor, Collider support)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string reason;
			return SpotClear(floor, support, out reason);
		}

		internal static bool SpotClear(Vector3 floor, Collider support, out string reason)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			reason = null;
			if ((Object)(object)support == (Object)null)
			{
				reason = "Sem apoio validado";
				return false;
			}
			Collider[] array = Physics.OverlapCapsule(floor + Vector3.up * 1.5f, floor + Vector3.up * 3.2f, 1.15f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)support)
				{
					reason = "Corpo bloqueado por " + ((Object)((Component)val).gameObject).name + " acima do pisoY=" + floor.y;
					return false;
				}
			}
			return true;
		}
	}
	public static class ArenaCatalog
	{
		public const float CenterX = -17f;

		public const float CenterZ = 1874.7f;

		public const float AttackRadius = 40f;

		public const float BeamRange = 50f;

		public static readonly TurretSpec[] All = Create();

		private static TurretSpec[] Create()
		{
			TurretSpec[] array = new TurretSpec[8];
			int[] array2 = new int[4] { 0, 2, 3, 4 };
			float[] array3 = new float[4] { -21f, -7f, 7f, 21f };
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					TurretSpec turretSpec = TurretCatalog.All[array2[j]];
					string text = ((i == 0) ? "oeste" : "leste");
					array[i * 4 + j] = new TurretSpec(turretSpec.Id + "_" + text, turretSpec.Name + " - " + text, -1800 + ((i == 0) ? (-32) : 32), 78f + array3[j], turretSpec.Health, 50f, turretSpec.Damage, turretSpec.Impact, turretSpec.Warning, turretSpec.Fire, turretSpec.Cooldown, turretSpec.Element, turretSpec.Status, turretSpec.Buildup, turretSpec.Shape, turretSpec.Scale, turretSpec.Red, turretSpec.Green, turretSpec.Blue);
				}
			}
			return array;
		}

		public static bool IsCombatPosition(float x, float y, float z)
		{
			float num = x - -17f;
			float num2 = z - 1874.7f;
			if (y >= 200f && y <= 280f)
			{
				return num * num + num2 * num2 <= 1600f;
			}
			return false;
		}
	}
	internal sealed class ArenaPlayerCandidates
	{
		private static readonly Vector3 Center = new Vector3(-17f, 255f, 1874.7f);

		private List<Character> _arena = new List<Character>();

		private List<Character> _fallback = new List<Character>();

		private CharacterManager _manager;

		private int _frame = -1;

		internal List<Character> Query(Vector3 point, float radius)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			CharacterManager instance = CharacterManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Reset();
				return _arena;
			}
			Vector3 val = point - Center;
			if (((Vector3)(ref val)).magnitude + radius > 256f)
			{
				_fallback.Clear();
				instance.FindCharactersInRange(point, radius, ref _fallback);
				return _fallback;
			}
			if (_frame != Time.frameCount || (Object)(object)_manager != (Object)(object)instance)
			{
				_arena.Clear();
				instance.FindCharactersInRange(Center, 256f, ref _arena);
				_manager = instance;
				_frame = Time.frameCount;
			}
			return _arena;
		}

		internal void Reset()
		{
			_frame = -1;
			_manager = null;
			_arena.Clear();
			_fallback.Clear();
		}
	}
	public enum TurretElement
	{
		Electric,
		Decay,
		Fire,
		Frost
	}
	public enum TurretShape
	{
		Original,
		Viper,
		Emerald,
		Ember,
		Aurora
	}
	public sealed class TurretSpec
	{
		public readonly string Id;

		public readonly string Name;

		public readonly string Status;

		public readonly float X;

		public readonly float Z;

		public readonly float Health;

		public readonly float Range;

		public readonly float Damage;

		public readonly float Impact;

		public readonly float Warning;

		public readonly float Fire;

		public readonly float Cooldown;

		public readonly float Buildup;

		public readonly float Scale;

		public readonly float Red;

		public readonly float Green;

		public readonly float Blue;

		public readonly TurretElement Element;

		public readonly TurretShape Shape;

		public TurretSpec(string id, string name, float x, float z, float health, float range, float damage, float impact, float warning, float fire, float cooldown, TurretElement element, string status, float buildup, TurretShape shape, float scale, float red, float green, float blue)
		{
			Id = id;
			Name = name;
			X = x;
			Z = z;
			Health = health;
			Range = range;
			Damage = damage;
			Impact = impact;
			Warning = warning;
			Fire = fire;
			Cooldown = cooldown;
			Element = element;
			Status = status;
			Buildup = buildup;
			Shape = shape;
			Scale = scale;
			Red = red;
			Green = green;
			Blue = blue;
		}
	}
	public static class TurretCatalog
	{
		public static readonly TurretSpec[] All = new TurretSpec[5]
		{
			new TurretSpec("azul", "Sentinela Runica de Treino", -18f, -40f, 1f, 12f, 12f, 8f, 1.1f, 0.45f, 3.2f, TurretElement.Electric, null, 0f, TurretShape.Original, 1f, 0.15f, 0.65f, 1f),
			new TurretSpec("vibora", "Vibora", 18f, -44f, 24f, 8f, 6f, 0f, 0.25f, 0.16f, 0.55f, TurretElement.Decay, "Poisoned", 35f, TurretShape.Viper, 1.1f, 0.38f, 1f, 0.08f),
			new TurretSpec("esmeralda", "Esmeralda", 46f, -9f, 32f, 16f, 8f, 0f, 0.55f, 0.22f, 1.1f, TurretElement.Decay, "Poisoned", 100f, TurretShape.Emerald, 1.15f, 0.04f, 0.86f, 0.34f),
			new TurretSpec("brasa", "Brasa", -46f, 8f, 45f, 18f, 14f, 6f, 0.8f, 0.35f, 2.2f, TurretElement.Fire, "Burning", 100f, TurretShape.Ember, 1.2f, 1f, 0.12f, 0.04f),
			new TurretSpec("aurora", "Aurora", 22f, 39f, 60f, 28f, 22f, 14f, 1.4f, 0.45f, 4.2f, TurretElement.Frost, null, 0f, TurretShape.Aurora, 1.35f, 0.8f, 0.94f, 1f)
		};
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexChefeFornalha
{
	public static class FurnaceCombos
	{
		public static readonly FurnaceBlow[][] Close = new FurnaceBlow[8][]
		{
			new FurnaceBlow[2]
			{
				FurnaceBlow.Right,
				FurnaceBlow.Left
			},
			new FurnaceBlow[3]
			{
				FurnaceBlow.Right,
				FurnaceBlow.Left,
				FurnaceBlow.Heavy
			},
			new FurnaceBlow[2]
			{
				FurnaceBlow.Delayed,
				FurnaceBlow.Left
			},
			new FurnaceBlow[3]
			{
				FurnaceBlow.Right,
				FurnaceBlow.Left,
				FurnaceBlow.Slam
			},
			new FurnaceBlow[3]
			{
				FurnaceBlow.Left,
				FurnaceBlow.Right,
				FurnaceBlow.HeavyLeft
			},
			new FurnaceBlow[3]
			{
				FurnaceBlow.Left,
				FurnaceBlow.Delayed,
				FurnaceBlow.Left
			},
			new FurnaceBlow[3]
			{
				FurnaceBlow.HeavyLeft,
				FurnaceBlow.Right,
				FurnaceBlow.Shot
			},
			new FurnaceBlow[4]
			{
				FurnaceBlow.Right,
				FurnaceBlow.Left,
				FurnaceBlow.Right,
				FurnaceBlow.Heavy
			}
		};

		public static readonly FurnaceBlow[][] Fury = new FurnaceBlow[2][]
		{
			new FurnaceBlow[4]
			{
				FurnaceBlow.Right,
				FurnaceBlow.Left,
				FurnaceBlow.HeavyLeft,
				FurnaceBlow.Slam
			},
			new FurnaceBlow[4]
			{
				FurnaceBlow.Left,
				FurnaceBlow.Right,
				FurnaceBlow.Shot,
				FurnaceBlow.Slam
			}
		};

		public static readonly FurnaceBlow[] Shot = new FurnaceBlow[1] { FurnaceBlow.Shot };

		public static readonly FurnaceBlow[] DoubleShot = new FurnaceBlow[2]
		{
			FurnaceBlow.Shot,
			FurnaceBlow.Shot
		};

		public static FurnaceBlow[] Select(int cycle, bool rage)
		{
			int num = cycle % (Close.Length + (rage ? Fury.Length : 0));
			if (num >= Close.Length)
			{
				return Fury[num - Close.Length];
			}
			return Close[num];
		}
	}
	internal sealed class InvisibleReceiver : MonoBehaviour
	{
		private readonly List<Renderer> _renderers = new List<Renderer>();

		private float _refresh;

		private void LateUpdate()
		{
			if (Time.time >= _refresh)
			{
				((Component)this).GetComponentsInChildren<Renderer>(true, _renderers);
				_refresh = Time.time + 0.1f;
			}
			foreach (Renderer renderer in _renderers)
			{
				if ((Object)(object)renderer != (Object)null && renderer.enabled)
				{
					renderer.enabled = false;
				}
			}
		}
	}
	internal sealed class FurnaceEnemy : MonoBehaviour
	{
		private Character _body;

		private FurnaceMotor _motor;

		private FurnaceFx _fx;

		private FurnaceRig _rig;

		private Collider[] _nativeColliders;

		private Rigidbody[] _rigidbodies;

		private Renderer[] _visual;

		private Hitbox _receiver;

		private SphereCollider _locking;

		private bool _victoryReported;

		private bool _shuttingDown;

		private float _health;

		private float _report;

		private float _visibility;

		private readonly List<FurnaceProjectile> _shots = new List<FurnaceProjectile>();

		private List<Character> _targets = new List<Character>();

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

		internal void Initialize(Character body)
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_015e: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Expected O, but got Unknown
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			_body = body;
			CharacterAI component = ((Component)body).GetComponent<CharacterAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			NavMeshAgent component2 = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			CharacterControl component3 = ((Component)body).GetComponent<CharacterControl>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			if ((Object)(object)body.CharacterController != (Object)null)
			{
				((Collider)body.CharacterController).enabled = false;
			}
			_nativeColliders = ((Component)body).GetComponentsInChildren<Collider>(true);
			Collider[] nativeColliders = _nativeColliders;
			for (int i = 0; i < nativeColliders.Length; i++)
			{
				nativeColliders[i].enabled = false;
			}
			_rigidbodies = ((Component)body).GetComponentsInChildren<Rigidbody>(true);
			Rigidbody[] rigidbodies = _rigidbodies;
			foreach (Rigidbody obj in rigidbodies)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			int num = LayerMask.NameToLayer("Hitbox");
			int num2 = LayerMask.NameToLayer("LockingPoints");
			if (num < 0 || num2 < 0 || (Global.LockingPointsMask & (1 << num2)) == 0)
			{
				throw new InvalidOperationException("Native damage/lock layers absent");
			}
			GameObject val = new GameObject("Fornalha_ReceptorDano");
			val.transform.SetParent(((Component)body).transform, false);
			val.layer = num;
			CapsuleCollider obj2 = val.AddComponent<CapsuleCollider>();
			obj2.radius = 1.55f;
			obj2.height = 4.6f;
			obj2.center = Vector3.up * 2.3f;
			((Collider)obj2).isTrigger = true;
			_receiver = val.AddComponent<Hitbox>();
			_receiver.OwnerChar = body;
			_receiver.Melee = true;
			_receiver.Ranged = true;
			FieldInfo? field = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("Character.m_hitboxes");
			}
			field.SetValue(body, new Hitbox[1] { _receiver });
			GameObject val2 = new GameObject("Fornalha_MiraNativa");
			val2.transform.SetParent(((Component)body).transform, false);
			val2.transform.localPosition = Vector3.up * 2.6f;
			val2.layer = num2;
			_locking = val2.AddComponent<SphereCollider>();
			_locking.radius = 0.2f;
			((Collider)_locking).isTrigger = true;
			LockingPoint obj3 = val2.AddComponent<LockingPoint>();
			obj3.OwnerChar = body;
			obj3.HideFlare = false;
			((Component)this).gameObject.layer = ((Component)body).gameObject.layer;
			CharacterController val3 = ((Component)this).gameObject.AddComponent<CharacterController>();
			val3.radius = 1.15f;
			val3.height = 4.3f;
			val3.center = Vector3.up * 2.15f;
			val3.skinWidth = 0.025f;
			val3.stepOffset = 0.3f;
			val3.slopeLimit = 45f;
			val3.minMoveDistance = 0f;
			FurnaceRig rig = (_rig = ((Component)this).GetComponent<FurnaceRig>());
			_fx = ((Component)this).gameObject.AddComponent<FurnaceFx>();
			_fx.Initialize(rig);
			Renderer[] componentsInChildren = (Renderer[])(object)((Component)this).GetComponentsInChildren<MeshRenderer>();
			_visual = componentsInChildren;
			_motor = ((Component)this).gameObject.AddComponent<FurnaceMotor>();
			_motor.Initialize(rig, val3);
			_motor.Target = delegate
			{
				//IL_0006: 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)
				Character val4 = Plugin.NearestPlayer(((Component)this).transform.position, 40f, combat: true);
				return (!((Object)(object)val4 == (Object)null)) ? new Vector3?(((Component)val4).transform.position) : ((Vector3?)null);
			};
			_motor.Paused = Plugin.Paused;
			_motor.Impact = Impact;
			_motor.Warning = _fx.Warn;
			_motor.Charge = _fx.Charge;
			_motor.RageChanged = _fx.Rage;
			_motor.Trace = Plugin.Instance.Diagnostic;
			_health = body.Stats.CurrentHealth;
			body.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(NativeDeath));
		}

		private void Update()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || (Object)(object)_motor == (Object)null)
			{
				return;
			}
			if (!_body.Alive)
			{
				NativeDeath();
			}
			float currentHealth = _body.Stats.CurrentHealth;
			if (currentHealth < _health && !_motor.Dead)
			{
				_motor.Hurt(_health - currentHealth);
			}
			_health = currentHealth;
			_motor.SetHealth(currentHealth);
			if (Time.time >= _visibility)
			{
				bool flag = (Object)(object)Plugin.NearestPlayer(((Component)this).transform.position, 150f, combat: false) != (Object)null;
				Renderer[] visual = _visual;
				foreach (Renderer val in visual)
				{
					if ((Object)(object)val != (Object)null && val.enabled != flag)
					{
						val.enabled = flag;
					}
				}
				_rig.SetVisible(flag);
				_fx.Visible(flag);
				_visibility = Time.time + 0.25f;
			}
			_shots.RemoveAll((FurnaceProjectile p) => (Object)(object)p == (Object)null);
			if (Plugin.Instance.Detailed && Time.time >= _report)
			{
				Plugin.Instance.Message("ESTADO=" + _motor.Phase + ";pos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString() + ";andou=" + _motor.DistanceWalked.ToString("F1") + "m;vida=" + currentHealth);
				_report = Time.time + 15f;
			}
		}

		private void Impact(FurnaceBlow blow)
		{
			//IL_0075: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0153: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || !_body.Alive || _motor.Dead || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			if (blow == FurnaceBlow.Shot)
			{
				Shoot();
				return;
			}
			bool flag = blow == FurnaceBlow.Slam;
			if (flag)
			{
				_fx.Blast();
			}
			_targets.Clear();
			_hit.Clear();
			CharacterManager.Instance.FindCharactersInRange(((Component)this).transform.position, (float)(flag ? 6 : 4), ref _targets);
			foreach (Character target in _targets)
			{
				if (!Valid(target) || !_hit.Add(target))
				{
					continue;
				}
				Vector3 val = ((Component)target).transform.position - ((Component)this).transform.position;
				if (Mathf.Abs(val.y) > 2.5f)
				{
					continue;
				}
				val.y = 0f;
				if (((Vector3)(ref val)).magnitude > (flag ? 6f : 3.8f) || (!flag && Vector3.Angle(((Component)this).transform.forward, val) > 60f) || Physics.Linecast(((Component)this).transform.position + Vector3.up * 2.6f, target.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
				{
					continue;
				}
				if (flag)
				{
					target.ReceiveHit((Object)null, new DamageList((Types)5, 30f), ((Vector3)(ref val)).normalized, target.CenterPosition, 45f, 1f, _body, 50f, true);
					if (Plugin.Instance.Detailed)
					{
						Plugin.Instance.Message("ABALO:30fogo/50impacto,nao bloqueavel," + target.Name);
					}
					continue;
				}
				float damage = blow switch
				{
					FurnaceBlow.Left => 26, 
					FurnaceBlow.Right => 22, 
					_ => 34, 
				};
				float impact = blow switch
				{
					FurnaceBlow.Left => 35, 
					FurnaceBlow.Right => 25, 
					_ => 55, 
				};
				bool flag2 = PhysicalContactHit.Apply((MonoBehaviour)(object)this, _body, target, damage, ((Vector3)(ref val)).normalized, impact, blockable: true);
				if (Plugin.Instance.Detailed)
				{
					Plugin.Instance.Message("CONTATO:" + blow.ToString() + " " + (flag2 ? "BLOQUEADO" : "ACERTOU") + ";" + damage + "fisico/" + impact + "impacto;" + target.Name);
				}
			}
		}

		private bool Valid(Character target)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target != (Object)null && (Object)(object)target != (Object)(object)_body && target.IsLocalPlayer && target.Alive)
			{
				return ArenaCatalog.IsCombatPosition(((Component)target).transform.position.x, ((Component)target).transform.position.y, ((Component)target).transform.position.z);
			}
			return false;
		}

		private void Shoot()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			_shots.RemoveAll((FurnaceProjectile p) => (Object)(object)p == (Object)null);
			if (_shots.Count < 2)
			{
				FurnaceProjectile shot = new GameObject("Fornalha_Projetil").AddComponent<FurnaceProjectile>();
				((Component)shot).transform.position = _fx.LaunchPoint;
				_shots.Add(shot);
				shot.Victim = IsVictim;
				shot.Hit = ShotHit;
				shot.Paused = Plugin.Paused;
				shot.Visible = () => (Object)(object)Plugin.NearestPlayer(((Component)shot).transform.position, 150f, combat: false) != (Object)null;
				shot.Initialize(_motor.Aim, Global.GeneralEnvironmentMask, 1 << LayerMask.NameToLayer("Hitbox"));
				if (Plugin.Instance.Detailed)
				{
					Plugin.Instance.Message("BOLA_FOGO:26fogo/12impacto,14m/s,36m,nao teleguiada.");
				}
			}
		}

		private bool IsVictim(Collider col)
		{
			if ((Object)(object)col == (Object)null)
			{
				return false;
			}
			Hitbox componentInParent = ((Component)col).GetComponentInParent<Hitbox>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return Valid(componentInParent.OwnerChar);
			}
			return false;
		}

		private void ShotHit(Collider col, Vector3 position)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			if (!((Object)(object)_body == (Object)null) && _body.Alive && !_motor.Dead && IsVictim(col))
			{
				Character ownerChar = ((Component)col).GetComponentInParent<Hitbox>().OwnerChar;
				DamageList val = new DamageList((Types)5, 26f);
				Vector3 val2 = ownerChar.CenterPosition - ((Component)this).transform.position;
				ownerChar.ReceiveHit((Object)null, val, ((Vector3)(ref val2)).normalized, position, 45f, 1f, _body, 12f, true);
				if (Plugin.Instance.Detailed)
				{
					Plugin.Instance.Message("BOLA_FOGO acertou " + ownerChar.Name + ",nao bloqueavel.");
				}
			}
		}

		private void Dead()
		{
			if ((Object)(object)_motor != (Object)null)
			{
				_motor.Kill();
			}
			if ((Object)(object)_fx != (Object)null)
			{
				_fx.Stop();
			}
			foreach (FurnaceProjectile shot in _shots)
			{
				if ((Object)(object)shot != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)shot).gameObject);
				}
			}
			_shots.Clear();
		}

		private void NativeDeath()
		{
			Dead();
			if (!_shuttingDown && !_victoryReported && !((Object)(object)_body == (Object)null) && !((Object)(object)_body.Stats == (Object)null) && !(_body.Stats.CurrentHealth > 0f))
			{
				_victoryReported = true;
				Plugin.ReportVictory(_body);
			}
		}

		internal void Shutdown()
		{
			_shuttingDown = true;
			Dead();
			if ((Object)(object)_motor != (Object)null)
			{
				((Behaviour)_motor).enabled = false;
			}
		}

		private void LateUpdate()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || (Object)(object)_motor == (Object)null)
			{
				return;
			}
			((Component)_body).transform.SetPositionAndRotation(((Component)this).transform.position, ((Component)this).transform.rotation);
			Rigidbody[] rigidbodies = _rigidbodies;
			foreach (Rigidbody val in rigidbodies)
			{
				if ((Object)(object)val != (Object)null)
				{
					if (!val.isKinematic)
					{
						val.isKinematic = true;
					}
					if (val.useGravity)
					{
						val.useGravity = false;
					}
				}
			}
			Collider[] nativeColliders = _nativeColliders;
			foreach (Collider val2 in nativeColliders)
			{
				if ((Object)(object)val2 != (Object)null && val2.enabled)
				{
					val2.enabled = false;
				}
			}
			if ((Object)(object)_receiver != (Object)null && ((Component)_receiver).gameObject.activeSelf == _motor.Dead)
			{
				((Component)_receiver).gameObject.SetActive(!_motor.Dead);
			}
			if ((Object)(object)_locking != (Object)null && ((Collider)_locking).enabled == _motor.Dead)
			{
				((Collider)_locking).enabled = !_motor.Dead;
			}
		}

		private void OnDestroy()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			_shuttingDown = true;
			if ((Object)(object)_body != (Object)null)
			{
				Character body = _body;
				body.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(NativeDeath));
			}
			Dead();
		}
	}
	internal sealed class FurnaceFx : MonoBehaviour
	{
		private Material _metal;

		private Material _ember;

		private Material _warning;

		private Transform _core;

		private Light _light;

		private LineRenderer _ring;

		private float _remaining;

		private float _length;

		private float _blast;

		private bool _rage;

		private bool _charging;

		private bool _alive = true;

		private bool _visible = true;

		private readonly Vector3[] _circle = (Vector3[])(object)new Vector3[96];

		private readonly Vector3[] _ringPoints = (Vector3[])(object)new Vector3[96];

		private Vector3 _floor;

		private Vector3 _floorAt;

		private Vector3 _drawnFloor;

		private float _drawnRadius = -1f;

		private bool _floorValid;

		internal Vector3 LaunchPoint => _core.position + ((Component)this).transform.forward * 0.45f;

		internal void Initialize(FurnaceRig rig)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00f5: 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_0135: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: 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)
			_metal = new Material(Shader.Find("Standard"))
			{
				color = new Color(0.32f, 0.16f, 0.065f)
			};
			_metal.SetFloat("_Metallic", 0.8f);
			_metal.SetFloat("_Glossiness", 0.48f);
			_ember = new Material(Shader.Find("Standard"))
			{
				color = new Color(1f, 0.25f, 0.035f)
			};
			_ember.EnableKeyword("_EMISSION");
			_ember.SetColor("_EmissionColor", new Color(2f, 0.35f, 0.025f));
			_warning = new Material(Shader.Find("Sprites/Default"));
			Transform parent = rig.Bone("Bone.002");
			_core = Part("Nucleo_Fornalha", (PrimitiveType)0, parent, new Vector3(0f, 2.75f, 1f), new Vector3(0.52f, 0.52f, 0.3f), _ember);
			Part("Aro_Nucleo", (PrimitiveType)2, parent, new Vector3(0f, 2.75f, 0.89f), new Vector3(0.72f, 0.065f, 0.72f), _metal).rotation = ((Component)this).transform.rotation * Quaternion.Euler(90f, 0f, 0f);
			string[] array = new string[2] { "Bone.001_L.003", "Bone.001_R.003" };
			foreach (string name in array)
			{
				Transform val = rig.Bone(name);
				if ((Object)(object)val != (Object)null)
				{
					GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
					((Object)obj).name = "Junta_Cobre";
					obj.transform.SetParent(val, false);
					obj.transform.localScale = new Vector3(0.42f, 0.25f, 0.42f);
					Finish(obj, _metal);
				}
			}
			_light = ((Component)_core).gameObject.AddComponent<Light>();
			_light.color = new Color(1f, 0.31f, 0.065f);
			_light.range = 5f;
			_light.intensity = 0.7f;
			_light.shadows = (LightShadows)0;
			GameObject val2 = new GameObject("Aviso_Abalo_6m");
			val2.transform.SetParent(((Component)this).transform, false);
			_ring = val2.AddComponent<LineRenderer>();
			((Renderer)_ring).sharedMaterial = _warning;
			_ring.useWorldSpace = true;
			_ring.loop = true;
			_ring.positionCount = 96;
			_ring.widthMultiplier = 0.12f;
			((Renderer)_ring).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)_ring).enabled = false;
			for (int j = 0; j < _circle.Length; j++)
			{
				float num = (float)j * (float)Math.PI * 2f / (float)_circle.Length;
				_circle[j] = new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num));
			}
		}

		private Transform Part(string name, PrimitiveType shape, Transform parent, Vector3 rootPosition, Vector3 scale, Material material)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(shape);
			((Object)obj).name = name;
			obj.transform.position = ((Component)this).transform.TransformPoint(rootPosition);
			obj.transform.rotation = ((Component)this).transform.rotation;
			obj.transform.localScale = scale;
			obj.transform.SetParent(parent, true);
			Finish(obj, material);
			return obj.transform;
		}

		private static void Finish(GameObject go, Material material)
		{
			Collider component = go.GetComponent<Collider>();
			component.enabled = false;
			Object.Destroy((Object)(object)component);
			Renderer component2 = go.GetComponent<Renderer>();
			component2.sharedMaterial = material;
			component2.shadowCastingMode = (ShadowCastingMode)0;
		}

		internal void Warn(float duration)
		{
			_remaining = (_length = duration);
			if (duration > 0f)
			{
				_floorValid = false;
			}
		}

		internal void Charge(bool value)
		{
			_charging = value;
		}

		internal void Rage(bool value)
		{
			_rage = value;
		}

		internal void Blast()
		{
			_blast = 0.5f;
			_floorValid = false;
		}

		internal void Visible(bool value)
		{
			_visible = value;
		}

		internal void Stop()
		{
			_alive = false;
			_remaining = 0f;
			_blast = 0f;
			if ((Object)(object)_light != (Object)null)
			{
				((Behaviour)_light).enabled = false;
			}
			if ((Object)(object)_ring != (Object)null)
			{
				((Renderer)_ring).enabled = false;
			}
		}

		private void Update()
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: 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_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ring == (Object)null)
			{
				return;
			}
			if (!Plugin.Paused())
			{
				_remaining = Mathf.Max(0f, _remaining - Mathf.Min(Time.deltaTime, 0.25f));
				_blast = Mathf.Max(0f, _blast - Mathf.Min(Time.deltaTime, 0.25f));
			}
			((Behaviour)_light).enabled = _alive && _visible;
			float num = (_charging ? 2.1f : (_rage ? 1.1f : 0.7f));
			_light.intensity = num + Mathf.Sin(Time.time * 5f) * 0.12f;
			((Renderer)_ring).enabled = _alive && _visible && (_remaining > 0f || _blast > 0f);
			if (!((Renderer)_ring).enabled)
			{
				return;
			}
			Color val = (_ring.startColor = (_ring.endColor = Color.Lerp(new Color(1f, 0.55f, 0.1f, 0.7f), new Color(1f, 0.12f, 0.02f, 0.95f), 1f - _remaining / Mathf.Max(0.01f, _length))));
			if (_blast > 0f)
			{
				LineRenderer ring = _ring;
				LineRenderer ring2 = _ring;
				((Color)(ref val))..ctor(1f, 0.4f, 0.02f, _blast * 2f);
				ring2.endColor = val;
				ring.startColor = val;
			}
			Vector3 val4;
			if (_floorValid)
			{
				val4 = ((Component)this).transform.position - _floorAt;
				if (!(((Vector3)(ref val4)).sqrMagnitude > 0.0001f))
				{
					goto IL_022e;
				}
			}
			if (!ArenaPlacement.TrySurface(((Component)this).transform.position, out _floor, out var _))
			{
				((Renderer)_ring).enabled = false;
				return;
			}
			_floorAt = ((Component)this).transform.position;
			_floorValid = true;
			goto IL_022e;
			IL_022e:
			float num2 = ((_blast > 0f) ? (6f * (1f - _blast / 0.5f)) : 6f);
			if (num2 == _drawnRadius)
			{
				val4 = _floor - _drawnFloor;
				if (!(((Vector3)(ref val4)).sqrMagnitude > 1E-06f))
				{
					return;
				}
			}
			for (int i = 0; i < _circle.Length; i++)
			{
				_ringPoints[i] = _floor + Vector3.up * 0.035f + _circle[i] * num2;
			}
			_ring.SetPositions(_ringPoints);
			_drawnFloor = _floor;
			_drawnRadius = num2;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_metal != (Object)null)
			{
				Object.Destroy((Object)(object)_metal);
			}
			if ((Object)(object)_ember != (Object)null)
			{
				Object.Destroy((Object)(object)_ember);
			}
			if ((Object)(object)_warning != (Object)null)
			{
				Object.Destroy((Object)(object)_warning);
			}
		}
	}
	public struct RigPose
	{
		public Vector3 Position;

		public Vector3 Scale;

		public Quaternion Rotation;

		public Matrix4x4 Matrix => Matrix4x4.TRS(Position, Rotation, Scale);

		public static RigPose Blend(RigPose a, RigPose b, float t)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			return new RigPose
			{
				Position = Vector3.Lerp(a.Position, b.Position, t),
				Rotation = Quaternion.Slerp(a.Rotation, b.Rotation, t),
				Scale = Vector3.Lerp(a.Scale, b.Scale, t)
			};
		}
	}
	public sealed class RigClip
	{
		public string Name;

		public float Duration;

		public bool Loop;

		public RigPose[][] Frames;

		public RigPose Sample(int bone, float time)
		{
			time = (Loop ? Mathf.Repeat(time, Duration) : Mathf.Clamp(time, 0f, Duration));
			float num = time / Duration * (float)(Frames.Length - 1);
			int num2 = Mathf.Min((int)num, Frames.Length - 1);
			int num3 = Mathf.Min(num2 + 1, Frames.Length - 1);
			return RigPose.Blend(Frames[num2][bone], Frames[num3][bone], num - (float)num2);
		}

		public void SampleInto(float time, RigPose[] destination)
		{
			time = (Loop ? Mathf.Repeat(time, Duration) : Mathf.Clamp(time, 0f, Duration));
			float num = time / Duration * (float)(Frames.Length - 1);
			int num2 = Mathf.Min((int)num, Frames.Length - 1);
			int num3 = Mathf.Min(num2 + 1, Frames.Length - 1);
			for (int i = 0; i < destination.Length; i++)
			{
				destination[i] = RigPose.Blend(Frames[num2][i], Frames[num3][i], num - (float)num2);
			}
		}
	}
	public sealed class FurnaceModel
	{
		public string[] Names;

		public int[] Parents;

		public int[] Triangles;

		public RigPose[] Rest;

		public Vector3[] Vertices;

		public Vector3[] Normals;

		public Vector2[] UV;

		public int[][] Indices;

		public float[][] Weights;

		public Dictionary<string, RigClip> Clips = new Dictionary<string, RigClip>();

		public static FurnaceModel Load(string path)
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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)
			FurnaceModel furnaceModel = new FurnaceModel();
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "CFURN001")
			{
				throw new InvalidDataException("Wrong external rig signature");
			}
			int num = Count(binaryReader, 1, 256);
			int num2 = Count(binaryReader, 3, 50000);
			int num3 = Count(binaryReader, 3, 300000);
			if (num3 % 3 != 0)
			{
				throw new InvalidDataException("Invalid triangle count");
			}
			furnaceModel.Names = new string[num];
			furnaceModel.Parents = new int[num];
			furnaceModel.Rest = new RigPose[num];
			for (int i = 0; i < num; i++)
			{
				furnaceModel.Names[i] = Text(binaryReader);
				int num4 = binaryReader.ReadInt32();
				if (num4 < -1 || num4 >= i)
				{
					throw new InvalidDataException("Bone parent order");
				}
				furnaceModel.Parents[i] = num4;
				furnaceModel.Rest[i] = Pose(binaryReader);
			}
			furnaceModel.Vertices = (Vector3[])(object)new Vector3[num2];
			furnaceModel.Normals = (Vector3[])(object)new Vector3[num2];
			furnaceModel.UV = (Vector2[])(object)new Vector2[num2];
			furnaceModel.Indices = new int[num2][];
			furnaceModel.Weights = new float[num2][];
			for (int j = 0; j < num2; j++)
			{
				furnaceModel.Vertices[j] = Vector(binaryReader);
				furnaceModel.Normals[j] = Vector(binaryReader);
				furnaceModel.UV[j] = new Vector2(Number(binaryReader), Number(binaryReader));
				int num5 = binaryReader.ReadByte();
				if (num5 < 1 || num5 > 64)
				{
					throw new InvalidDataException("Invalid skin weights");
				}
				furnaceModel.Indices[j] = new int[num5];
				furnaceModel.Weights[j] = new float[num5];
				float num6 = 0f;
				for (int k = 0; k < num5; k++)
				{
					int num7 = binaryReader.ReadInt32();
					float num8 = Number(binaryReader);
					if (num7 < 0 || num7 >= num || num8 <= 0f)
					{
						throw new InvalidDataException("Invalid bone influence");
					}
					furnaceModel.Indices[j][k] = num7;
					furnaceModel.Weights[j][k] = num8;
					num6 += num8;
				}
				if (Mathf.Abs(num6 - 1f) > 0.0001f)
				{
					throw new InvalidDataException("Skin weights not normalized");
				}
			}
			furnaceModel.Triangles = new int[num3];
			for (int l = 0; l < num3; l++)
			{
				int num9 = binaryReader.ReadInt32();
				if (num9 < 0 || num9 >= num2)
				{
					throw new InvalidDataException("Invalid triangle index");
				}
				furnaceModel.Triangles[l] = num9;
			}
			int num10 = Count(binaryReader, 1, 32);
			for (int m = 0; m < num10; m++)
			{
				string text = Text(binaryReader);
				float num11 = Number(binaryReader);
				bool loop = binaryReader.ReadBoolean();
				int num12 = Count(binaryReader, 2, 2000);
				if (num11 <= 0f || num11 > 120f || furnaceModel.Clips.ContainsKey(text))
				{
					throw new InvalidDataException("Invalid animation clip");
				}
				RigClip rigClip = new RigClip
				{
					Name = text,
					Duration = num11,
					Loop = loop,
					Frames = new RigPose[num12][]
				};
				for (int n = 0; n < num12; n++)
				{
					rigClip.Frames[n] = new RigPose[num];
					for (int num13 = 0; num13 < num; num13++)
					{
						rigClip.Frames[n][num13] = Pose(binaryReader);
					}
				}
				furnaceModel.Clips.Add(text, rigClip);
			}
			if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
			{
				throw new InvalidDataException("Unexpected rig trailing data");
			}
			string[] array = new string[6] { "Idle", "Walk", "Right", "Left", "Hurt", "Death" };
			foreach (string text2 in array)
			{
				if (!furnaceModel.Clips.ContainsKey(text2))
				{
					throw new InvalidDataException("Missing clip:" + text2);
				}
			}
			return furnaceModel;
		}

		private static int Count(BinaryReader reader, int min, int max)
		{
			int num = reader.ReadInt32();
			if (num < min || num > max)
			{
				throw new InvalidDataException("Rig count out of bounds");
			}
			return num;
		}

		private static string Text(BinaryReader reader)
		{
			int num = reader.ReadUInt16();
			if (num < 1 || num > 200)
			{
				throw new InvalidDataException("Rig name out of bounds");
			}
			byte[] array = reader.ReadBytes(num);
			if (array.Length != num)
			{
				throw new EndOfStreamException();
			}
			return Encoding.UTF8.GetString(array);
		}

		private static float Number(BinaryReader reader)
		{
			float num = reader.ReadSingle();
			if (float.IsNaN(num) || float.IsInfinity(num))
			{
				throw new InvalidDataException("Nonfinite rig data");
			}
			return num;
		}

		private static Vector3 Vector(BinaryReader reader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(Number(reader), Number(reader), Number(reader));
		}

		private static RigPose Pose(BinaryReader reader)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			RigPose result = new RigPose
			{
				Position = Vector(reader),
				Rotation = new Quaternion(Number(reader), Number(reader), Number(reader), Number(reader)),
				Scale = Vector(reader)
			};
			float num = Quaternion.Dot(result.Rotation, result.Rotation);
			if (result.Scale.x <= 0f || result.Scale.y <= 0f || result.Scale.z <= 0f || num < 0.99f || num > 1.01f)
			{
				throw new InvalidDataException("Invalid bone transform");
			}
			return result;
		}

		public void WorldMatrices(RigPose[] pose, Matrix4x4[] destination)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < pose.Length; i++)
			{
				destination[i] = ((Parents[i] < 0) ? pose[i].Matrix : (destination[Parents[i]] * pose[i].Matrix));
			}
		}

		public void Skin(Matrix4x4[] world, Matrix4x4[] inverseBind, Vector3[] points, Vector3[] normals)
		{
			Matrix4x4[] matrices = (Matrix4x4[])(object)new Matrix4x4[world.Length];
			Skin(world, inverseBind, matrices, points, normals);
		}

		public void Skin(Matrix4x4[] world, Matrix4x4[] inverseBind, Matrix4x4[] matrices, Vector3[] points, Vector3[] normals)
		{
			//IL_0008: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < world.Length; i++)
			{
				matrices[i] = world[i] * inverseBind[i];
			}
			for (int j = 0; j < Vertices.Length; j++)
			{
				Vector3 val = Vector3.zero;
				Vector3 val2 = Vector3.zero;
				for (int k = 0; k < Indices[j].Length; k++)
				{
					int num = Indices[j][k];
					Matrix4x4 val3 = matrices[num];
					float num2 = Weights[j][k];
					val += ((Matrix4x4)(ref val3)).MultiplyPoint3x4(Vertices[j]) * num2;
					val2 += ((Matrix4x4)(ref val3)).MultiplyVector(Normals[j]) * num2;
				}
				points[j] = val;
				normals[j] = ((Vector3)(ref val2)).normalized;
			}
		}
	}
	public sealed class FurnaceMotor : MonoBehaviour
	{
		public Func<Vector3?> Target;

		public Func<bool> Paused;

		public Action<FurnaceBlow> Impact;

		public Action<float> Warning;

		public Action<bool> Charge;

		public Action<bool> RageChanged;

		public Action<string> Trace;

		private CharacterController _controller;

		private FurnaceRig _rig;

		private readonly FurnaceTimeline _timeline = new FurnaceTimeline();

		private Vector3 _home;

		private Vector3 _velocity;

		private float _vertical;

		private float _clock;

		private float _nextShot = 1f;

		private float _lastHurt = -10f;

		private float _walk = 1f;

		private int _cycle;

		private const float Leash = 24f;

		private const float MoveSpeed = 3f;

		private const float RageMoveSpeed = 4f;

		private const float WalkReferenceSpeed = 1.45f;

		private static readonly float[] AvoidAngles = new float[2] { -65f, 65f };

		public bool Dead => _timeline.Phase == FurnacePhase.Dead;

		public bool Enraged { get; private set; }

		public float DistanceWalked { get; private set; }

		public string Phase { get; private set; } = "Idle";

		public Vector3 Aim { get; private set; }

		public void Initialize(FurnaceRig rig, CharacterController controller)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			_rig = rig;
			_controller = controller;
			_home = ((Component)this).transform.position;
			_rig.Paused = () => Paused != null && Paused();
		}

		public void SetHealth(float health)
		{
			bool flag = !Dead && health > 0f && health <= 750f;
			if (flag != Enraged)
			{
				Enraged = flag;
				_rig.SetRage(flag);
				RageChanged?.Invoke(flag);
				Trace?.Invoke("FURIA=" + flag + ";vida=" + health);
			}
		}

		public void Hurt(float damage)
		{
			if (!Dead && !(damage < 35f) && !(_clock - _lastHurt < 5f))
			{
				_lastHurt = _clock;
				Apply(_timeline.Cancel(_clock, 0.5f));
				_rig.Play("Hurt", 2.5f);
			}
		}

		public void Kill()
		{
			//IL_0020: 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)
			if (!Dead)
			{
				_timeline.Kill();
				Phase = "Dead";
				_velocity = Vector3.zero;
				Warning?.Invoke(0f);
				Charge?.Invoke(obj: false);
				_rig.Play("Death");
			}
		}

		private void Update()
		{
			//IL_0060: 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)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_controller == (Object)null) && ((Collider)_controller).enabled && (Paused == null || !Paused()))
			{
				float num = Mathf.Min(Time.deltaTime, 0.25f);
				_clock += num;
				Vector3 val = (Dead ? Vector3.zero : Think(num));
				_velocity = ((Phase == "Chase" || Phase == "Return") ? Vector3.MoveTowards(_velocity, val, 10f * num) : Vector3.zero);
				Vector3 position = ((Component)this).transform.position;
				int num2 = Mathf.Max(1, Mathf.CeilToInt(num / 0.025f));
				float num3 = num / (float)num2;
				for (int i = 0; i < num2; i++)
				{
					_vertical = (_controller.isGrounded ? (-2f) : Mathf.Max(_vertical - 22f * num3, -20f));
					_controller.Move((_velocity + Vector3.up * _vertical) * num3);
				}
				Vector3 val2 = ((Component)this).transform.position - position;
				val2.y = 0f;
				DistanceWalked += ((Vector3)(ref val2)).magnitude;
				if (Phase == "Chase" || Phase == "Return")
				{
					_walk = Mathf.MoveTowards(_walk, Mathf.Clamp(((Vector3)(ref val2)).magnitude / Mathf.Max(num, 0.0001f) / 1.45f, 0.15f, 3.2f), 5f * num);
					_rig.SetWalkSpeed(_walk);
				}
			}
		}

		private Vector3 Think(float dt)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: 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_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: 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_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			Vector3? val = Target?.Invoke();
			if (_timeline.Busy)
			{
				if (_timeline.Phase == FurnacePhase.Windup)
				{
					if (val.HasValue)
					{
						Vector3 val2 = val.Value - ((Component)this).transform.position;
						if (!(((Vector3)(ref val2)).magnitude > 40f))
						{
							Turn(val.Value - ((Component)this).transform.position, dt);
							goto IL_00aa;
						}
					}
					Apply(_timeline.Cancel(_clock));
					return Vector3.zero;
				}
				goto IL_00aa;
			}
			bool flag = !val.HasValue;
			Vector3 val3 = (flag ? _home : val.Value);
			Vector3 val4 = val3 - ((Component)this).transform.position;
			val4.y = 0f;
			float magnitude = ((Vector3)(ref val4)).magnitude;
			if (flag && magnitude < 0.2f)
			{
				Phase = "Idle";
				_rig.Play("Idle", 1f, 0f, restart: false);
				return Vector3.zero;
			}
			Turn(val4, dt);
			bool flag2 = !Physics.Linecast(((Component)this).transform.position + Vector3.up * 2.6f, val3 + Vector3.up, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			if (!flag && flag2 && Vector3.Angle(((Component)this).transform.forward, val4) < 25f)
			{
				if (magnitude <= 3.5f)
				{
					Begin(FurnaceCombos.Select(_cycle++, Enraged));
					return Vector3.zero;
				}
				if (magnitude >= 6f && magnitude <= 36f && _clock >= _nextShot)
				{
					Begin(Enraged ? FurnaceCombos.DoubleShot : FurnaceCombos.Shot);
					_nextShot = _clock + (Enraged ? 4.2f : 6f);
					return Vector3.zero;
				}
			}
			if (!flag)
			{
				Vector3 val5 = val3 - _home;
				val5.y = 0f;
				if (((Vector3)(ref val5)).magnitude > 24f)
				{
					val3 = _home + ((Vector3)(ref val5)).normalized * 24f;
				}
				val4 = val3 - ((Component)this).transform.position;
				val4.y = 0f;
				if (((Vector3)(ref val4)).magnitude < 0.3f)
				{
					Phase = "Idle";
					_rig.Play("Idle", 1f, 0f, restart: false);
					return Vector3.zero;
				}
			}
			Vector3 val6 = ((Vector3)(ref val4)).normalized;
			RaycastHit val7 = default(RaycastHit);
			if (Physics.SphereCast(((Component)this).transform.position + Vector3.up * 1.5f, 1.1f, val6, ref val7, 1.8f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				bool flag3 = false;
				float[] avoidAngles = AvoidAngles;
				foreach (float num in avoidAngles)
				{
					Vector3 val8 = Quaternion.Euler(0f, num, 0f) * val6;
					if (!Physics.SphereCast(((Component)this).transform.position + Vector3.up * 1.5f, 1.1f, val8, ref val7, 1.8f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
					{
						val6 = val8;
						flag3 = true;
						break;
					}
				}
				if (!flag3)
				{
					Phase = "Blocked";
					_rig.Play("Idle", 1f, 0f, restart: false);
					return Vector3.zero;
				}
			}
			Vector3 val9 = ((Component)this).transform.position + val6 * 1.8f;
			Vector3 val10 = val9 - _home;
			val10.y = 0f;
			if (((Vector3)(ref val10)).magnitude > 24.1f || !Physics.Raycast(val9 + Vector3.up * 0.6f, Vector3.down, 1.4f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				Phase = "Blocked";
				_rig.Play("Idle", 1f, 0f, restart: false);
				return Vector3.zero;
			}
			Turn(val6, dt);
			Phase = (flag ? "Return" : "Chase");
			_rig.Play("Walk", _walk, 0f, restart: false);
			return val6 * (Enraged ? 4f : 3f);
			IL_00aa:
			Apply(_timeline.Advance(_clock));
			Phase = _timeline.Phase.ToString();
			return Vector3.zero;
		}

		private void Begin(FurnaceBlow[] combo)
		{
			Apply(_timeline.Start(combo, _clock, _rig.Length("Right"), Enraged));
			Phase = _timeline.Phase.ToString();
		}

		private void Apply(FurnaceEvent events)
		{
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if ((events & FurnaceEvent.Windup) != FurnaceEvent.None)
			{
				_rig.Play(_timeline.Clip, 0f, 0.18f);
				bool obj = _timeline.Blow == FurnaceBlow.Shot;
				Charge?.Invoke(obj);
				Warning?.Invoke((_timeline.Blow == FurnaceBlow.Slam) ? _timeline.WarningDuration : 0f);
				Trace?.Invoke("PREPARO:" + _timeline.Blow.ToString() + ";aviso=" + _timeline.Windup.ToString("F2") + "s");
			}
			if ((events & FurnaceEvent.Strike) != FurnaceEvent.None)
			{
				Vector3? val = Target?.Invoke();
				Aim = (val.HasValue ? (val.Value + Vector3.up) : (((Component)this).transform.position + ((Component)this).transform.forward * 20f + Vector3.up));
				_rig.Play(_timeline.Clip, _timeline.Speed, 0.18f);
			}
			if ((events & FurnaceEvent.Impact) != FurnaceEvent.None)
			{
				Warning?.Invoke(0f);
				Charge?.Invoke(obj: false);
				Impact?.Invoke(_timeline.Blow);
			}
			if ((events & (FurnaceEvent.Recovery | FurnaceEvent.Idle)) != FurnaceEvent.None)
			{
				Warning?.Invoke(0f);
				Charge?.Invoke(obj: false);
				_rig.Play("Idle", 1f, 0f, restart: false);
			}
		}

		private void Turn(Vector3 direction, float dt)
		{
			//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_002c: 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)
			direction.y = 0f;
			if (((Vector3)(ref direction)).sqrMagnitude > 0.001f)
			{
				((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(direction), 180f * dt);
			}
		}
	}
	public sealed class FurnaceProjectile : MonoBehaviour
	{
		public Func<Collider, bool> Victim;

		public Action<Collider, Vector3> Hit;

		public Func<bool> Paused;

		public Func<bool> Visible;

		private const float Speed = 14f;

		private const float Range = 36f;

		private const float Radius = 0.25f;

		private Vector3 _velocity;

		private float _travel;

		private int _environment;

		private int _targets;

		private Material _material;

		private Material _trailMaterial;

		private Renderer _renderer;

		private TrailRenderer _trail;

		public bool Finished { get; private set; }

		public void Initialize(Vector3 aim, int environment, int targets)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = aim - ((Component)this).transform.position;
			_velocity = ((Vector3)(ref val)).normalized * 14f;
			_environment = environment;
			_targets = targets;
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val2).name = "Bola_Fornalha";
			val2.transform.SetParent(((Component)this).transform, false);
			Collider component = val2.GetComponent<Collider>();
			component.enabled = false;
			Object.Destroy((Object)(object)component);
			val2.transform.localScale = Vector3.one * 0.45f;
			_material = new Material(Shader.Find("Standard"))
			{
				color = new Color(1f, 0.32f, 0.035f)
			};
			_material.EnableKeyword("_EMISSION");
			_material.SetColor("_EmissionColor", new Color(3f, 0.65f, 0.025f));
			_renderer = val2.GetComponent<Renderer>();
			_renderer.sharedMaterial = _material;
			_renderer.shadowCastingMode = (ShadowCastingMode)0;
			_trailMaterial = new Material(Shader.Find("Sprites/Default"));
			_trail = ((Component)this).gameObject.AddComponent<TrailRenderer>();
			((Renderer)_trail).sharedMaterial = _trailMaterial;
			_trail.time = 0.3f;
			_trail.startWidth = 0.4f;
			_trail.endWidth = 0f;
			_trail.startColor = new Color(1f, 0.45f, 0.035f, 0.9f);
			_trail.endColor = new Color(0.7f, 0.1f, 0.02f, 0f);
			((Renderer)_trail).shadowCastingMode = (ShadowCastingMode)0;
		}

		private void Update()
		{
			//IL_009b: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (Finished)
			{
				return;
			}
			bool enabled = Visible == null || Visible();
			_renderer.enabled = enabled;
			((Renderer)_trail).enabled = enabled;
			if (Paused != null && Paused())
			{
				return;
			}
			float num = Mathf.Min(Time.deltaTime, 0.25f);
			int num2 = Mathf.Max(1, Mathf.CeilToInt(num / 0.025f));
			for (int i = 0; i < num2; i++)
			{
				if (Finished)
				{
					break;
				}
				float num3 = Mathf.Min(14f * num / (float)num2, 36f - _travel);
				if (FindCollision(((Component)this).transform.position, ((Vector3)(ref _velocity)).normalized, num3, _environment, _targets, Victim, out var collider, out var point))
				{
					Finished = true;
					if (Victim != null && Victim(collider))
					{
						Hit?.Invoke(collider, point);
					}
					Object.Destroy((Object)(object)((Component)this).gameObject);
					break;
				}
				Transform transform = ((Component)this).transform;
				transform.position += ((Vector3)(ref _velocity)).normalized * num3;
				_travel += num3;
				if (_travel >= 36f)
				{
					Finished = true;
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		public static bool FindCollision(Vector3 start, Vector3 direction, float length, int environment, int targets, Func<Collider, bool> victim, out Collider collider, out Vector3 point)
		{
			//IL_0006: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			collider = null;
			point = start;
			float num = length + 0.001f;
			Collider[] array = Physics.OverlapSphere(start, 0.25f, environment | targets, (QueryTriggerInteraction)2);
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if (!val.isTrigger && (environment & (1 << ((Component)val).gameObject.layer)) != 0)
				{
					collider = val;
					return true;
				}
			}
			array2 = array;
			foreach (Collider val2 in array2)
			{
				if (victim != null && victim(val2))
				{
					collider = val2;
					return true;
				}
			}
			RaycastHit[] array3 = Physics.SphereCastAll(start, 0.25f, direction, length, environment | targets, (QueryTriggerInteraction)2);
			for (int i = 0; i < array3.Length; i++)
			{
				RaycastHit val3 = array3[i];
				if (((!((RaycastHit)(ref val3)).collider.isTrigger && (environment & (1 << ((Component)((RaycastHit)(ref val3)).collider).gameObject.layer)) != 0) || (victim != null && victim(((RaycastHit)(ref val3)).collider))) && !(((RaycastHit)(ref val3)).distance >= num))
				{
					num = ((RaycastHit)(ref val3)).distance;
					collider = ((RaycastHit)(ref val3)).collider;
					point = ((RaycastHit)(ref val3)).point;
				}
			}
			return (Object)(object)collider != (Object)null;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
			if ((Object)(object)_trailMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_trailMaterial);
			}
		}
	}
	public sealed class FurnaceRig : MonoBehaviour
	{
		private FurnaceModel _model;

		private RigPose[] _pose;

		private RigPose[] _blend;

		private RigPose[] _sample;

		private Matrix4x4[] _world;

		private Matrix4x4[] _inverseBind;

		private Matrix4x4[] _skinMatrices;

		private Vector3[] _points;

		private Vector3[] _normals;

		private Transform[] _bones;

		private Mesh _mesh;

		private Material _material;

		private Texture2D _texture;

		private Texture2D _normal;

		private MeshRenderer _renderer;

		private RigClip _clip;

		private float _time;

		private float _speed = 1f;

		private float _fade;

		private bool _visible = true;

		private bool _dirty = true;

		public Func<bool> Paused;

		public float Length(string name)
		{
			return _model.Clips[name].Duration;
		}

		public Transform Bone(string name)
		{
			int num = Array.IndexOf(_model.Names, name);
			if (num < 0)
			{
				throw new InvalidOperationException("External attachment bone missing:" + name);
			}
			return _bones[num];
		}

		public void Initialize(FurnaceModel model, byte[] texture, byte[] normal)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Expected O, but got Unknown
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			_model = model;
			int num = model.Names.Length;
			_pose = (RigPose[])model.Rest.Clone();
			_blend = new RigPose[num];
			_sample = new RigPose[num];
			_world = (Matrix4x4[])(object)new Matrix4x4[num];
			_inverseBind = (Matrix4x4[])(object)new Matrix4x4[num];
			_skinMatrices = (Matrix4x4[])(object)new Matrix4x4[num];
			_bones = (Transform[])(object)new Transform[num];
			_points = (Vector3[])(object)new Vector3[model.Vertices.Length];
			_normals = (Vector3[])(object)new Vector3[_points.Length];
			model.WorldMatrices(model.Rest, _world);
			for (int i = 0; i < num; i++)
			{
				_inverseBind[i] = ((Matrix4x4)(ref _world[i])).inverse;
			}
			for (int j = 0; j < num; j++)
			{
				Transform transform = new GameObject(model.Names[j]).transform;
				transform.SetParent((model.Parents[j] < 0) ? ((Component)this).transform : _bones[model.Parents[j]], false);
				_bones[j] = transform;
			}
			_mesh = new Mesh
			{
				name = "BeetleGolem_External_Animated_620tris"
			};
			_mesh.MarkDynamic();
			_mesh.vertices = model.Vertices;
			_mesh.normals = model.Normals;
			_mesh.uv = model.UV;
			_mesh.triangles = model.Triangles;
			_mesh.RecalculateBounds();
			_texture = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(_texture, texture, true))
			{
				throw new InvalidOperationException("External texture decode failed");
			}
			if (((Texture)_texture).width > 1024 || ((Texture)_texture).height > 1024)
			{
				throw new InvalidOperationException("Texture exceeds1K");
			}
			((Texture)_texture).filterMode = (FilterMode)2;
			((Texture)_texture).anisoLevel = 4;
			_material = new Material(Shader.Find("Standard"))
			{
				name = "Fornalha_Carapaca_Ferro_Privada",
				mainTexture = (Texture)(object)_texture,
				color = new Color(0.72f, 0.7f, 0.66f)
			};
			_material.SetFloat("_Metallic", 0.38f);
			_material.SetFloat("_Glossiness", 0.32f);
			_normal = new Texture2D(2, 2, (TextureFormat)4, true, true);
			if (!ImageConversion.LoadImage(_normal, normal, false) || ((Texture)_normal).width > 1024 || ((Texture)_normal).height > 1024)
			{
				throw new InvalidOperationException("External normal decode/size failed");
			}
			Color[] pixels = _normal.GetPixels();
			for (int k = 0; k < pixels.Length; k++)
			{
				pixels[k] = new Color(1f, pixels[k].g, 1f, pixels[k].r);
			}
			_normal.SetPixels(pixels);
			_normal.Apply(true, true);
			_material.SetTexture("_BumpMap", (Texture)(object)_normal);
			((Texture)_normal).filterMode = (FilterMode)2;
			((Texture)_normal).anisoLevel = 4;
			_material.SetFloat("_BumpScale", 0.85f);
			_material.EnableKeyword("_NORMALMAP");
			((Component)this).gameObject.AddComponent<MeshFilter>().sharedMesh = _mesh;
			_renderer = ((Component)this).gameObject.AddComponent<MeshRenderer>();
			((Renderer)_renderer).sharedMaterial = _material;
			((Renderer)_renderer).shadowCastingMode = (ShadowCastingMode)0;
			Play("Idle");
			_fade = 0f;
			Sample(0f);
		}

		public void Play(string name, float speed = 1f, float normalized = 0f, bool restart = true)
		{
			if (!restart && _clip != null && _clip.Name == name)
			{
				_speed = speed;
				return;
			}
			Array.Copy(_pose, _blend, _pose.Length);
			_fade = 0.12f;
			_clip = _model.Clips[name];
			_time = _clip.Duration * normalized;
			_speed = speed;
			_dirty = true;
		}

		public void SetWalkSpeed(float speed)
		{
			if (_clip != null && _clip.Name == "Walk")
			{
				_speed = speed;
			}
		}

		public void SetVisible(bool visible)
		{
			if (visible && !_visible)
			{
				_dirty = true;
			}
			_visible = visible;
			if ((Object)(object)_renderer != (Object)null)
			{
				((Renderer)_renderer).enabled = visible;
			}
		}

		public void SetRage(bool rage)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			_material.color = (rage ? new Color(0.85f, 0.62f, 0.45f) : new Color(0.72f, 0.7f, 0.66f));
		}

		private void LateUpdate()
		{
			if (_model != null && _clip != null && (Paused == null || !Paused()))
			{
				Sample(Mathf.Min(Time.deltaTime, 0.25f));
			}
		}

		public void Sample(float dt)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _speed != 0f && (_clip.Loop || _time < _clip.Duration);
			bool flag2 = _fade > 0f;
			_time += dt * _speed;
			_fade = Mathf.Max(0f, _fade - dt);
			if (_visible && (_dirty || flag || flag2))
			{
				_dirty = false;
				_clip.SampleInto(_time, _sample);
				for (int i = 0; i < _pose.Length; i++)
				{
					RigPose rigPose = _sample[i];
					_pose[i] = ((_fade > 0f) ? RigPose.Blend(_blend[i], rigPose, 1f - _fade / 0.12f) : rigPose);
					_bones[i].localPosition = _pose[i].Position;
					_bones[i].localRotation = _pose[i].Rotation;
					_bones[i].localScale = _pose[i].Scale;
				}
				_model.WorldMatrices(_pose, _world);
				_model.Skin(_world, _inverseBind, _skinMatrices, _points, _normals);
				_mesh.vertices = _points;
				_mesh.normals = _normals;
				_mesh.RecalculateTangents();
				_mesh.RecalculateBounds();
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_mesh != (Object)null)
			{
				Object.Destroy((Object)(object)_mesh);
			}
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
			if ((Object)(object)_texture != (Object)null)
			{
				Object.Destroy((Object)(object)_texture);
			}
			if ((Object)(object)_normal != (Object)null)
			{
				Object.Destroy((Object)(object)_normal);
			}
		}
	}
	public enum FurnaceBlow
	{
		Right,
		Left,
		Heavy,
		Delayed,
		Slam,
		Shot,
		HeavyLeft
	}
	public enum FurnacePhase
	{
		Idle,
		Windup,
		Strike,
		Gap,
		Recovery,
		Dead
	}
	[Flags]
	public enum FurnaceEvent
	{
		None = 0,
		Windup = 1,
		Strike = 2,
		Impact = 4,
		Recovery = 8,
		Idle = 0x10
	}
	public sealed class FurnaceTimeline
	{
		private FurnaceBlow[] _sequence;

		private int _index;

		private bool _hit;

		private bool _rage;

		private float _until;

		private float _impact;

		private float _duration;

		public FurnacePhase Phase { get; private set; }

		public FurnaceBlow Blow => _sequence[_index];

		public bool Busy
		{
			get
			{
				if (Phase != FurnacePhase.Idle)
				{
					return Phase != FurnacePhase.Dead;
				}
				return false;
			}
		}

		public string Clip
		{
			get
			{
				if (Blow != FurnaceBlow.Left && Blow != FurnaceBlow.HeavyLeft && Blow != FurnaceBlow.Slam)
				{
					return "Right";
				}
				return "Left";
			}
		}

		public float Speed => ((Blow == FurnaceBlow.Slam || Blow == FurnaceBlow.Shot) ? 1.55f : ((Blow == FurnaceBlow.Heavy || Blow == FurnaceBlow.HeavyLeft || Blow == FurnaceBlow.Delayed) ? 1.5f : 2.05f)) * (_rage ? 1.15f : 1f);

		public float ImpactFraction
		{
			get
			{
				if (Blow != FurnaceBlow.Slam)
				{
					if (Blow != FurnaceBlow.Shot)
					{
						return 0.43f;
					}
					return 0.55f;
				}
				return 0.65f;
			}
		}

		public float Windup => ((Blow == FurnaceBlow.Delayed) ? 1.15f : ((Blow == FurnaceBlow.Slam) ? 0.9f : ((Blow == FurnaceBlow.Shot) ? 1f : ((Blow == FurnaceBlow.Heavy || Blow == FurnaceBlow.HeavyLeft) ? 0.75f : 0.35f)))) * (_rage ? 0.85f : 1f);

		public float WarningDuration => Windup + _duration * (ImpactFraction - 0.18f) / Speed;

		public FurnaceEvent Start(FurnaceBlow[] sequence, float now, float duration, bool rage)
		{
			if (Phase == FurnacePhase.Dead || Busy)
			{
				return FurnaceEvent.None;
			}
			if (sequence == null || sequence.Length == 0 || duration <= 0f)
			{
				throw new ArgumentException("Invalid combo");
			}
			_sequence = (FurnaceBlow[])sequence.Clone();
			_index = 0;
			_duration = duration;
			_rage = rage;
			return Begin(now);
		}

		private FurnaceEvent Begin(float now)
		{
			_hit = false;
			Phase = FurnacePhase.Windup;
			_until = now + Windup;
			return FurnaceEvent.Windup;
		}

		public FurnaceEvent Advance(float now)
		{
			if (Phase == FurnacePhase.Windup && now >= _until)
			{
				Phase = FurnacePhase.Strike;
				_impact = now + _duration * (ImpactFraction - 0.18f) / Speed;
				_until = now + _duration * 0.82f / Speed;
				return FurnaceEvent.Strike;
			}
			if (Phase == FurnacePhase.Strike)
			{
				FurnaceEvent furnaceEvent = FurnaceEvent.None;
				if (!_hit && now >= _impact)
				{
					_hit = true;
					furnaceEvent |= FurnaceEvent.Impact;
				}
				if (now >= _until)
				{
					Phase = FurnacePhase.Gap;
					_until = now + 0.14f;
				}
				return furnaceEvent;
			}
			if (Phase == FurnacePhase.Gap && now >= _until)
			{
				if (++_index < _sequence.Length)
				{
					return Begin(now);
				}
				_index = _sequence.Length - 1;
				return Cancel(now, 1f * (_rage ? 0.85f : 1f));
			}
			if (Phase == FurnacePhase.Recovery && now >= _until)
			{
				Phase = FurnacePhase.Idle;
				return FurnaceEvent.Idle;
			}
			return FurnaceEvent.None;
		}

		public FurnaceEvent Cancel(float now, float recovery = 0.6f)
		{
			if (Phase == FurnacePhase.Dead)
			{
				return FurnaceEvent.None;
			}
			Phase = FurnacePhase.Recovery;
			_until = now + recovery;
			return FurnaceEvent.Recovery;
		}

		public void Kill()
		{
			Phase = FurnacePhase.Dead;
			_sequence = null;
		}
	}
	[BepInPlugin("codex.outward.chefe.fornalha", "Codex - Colosso da Fornalha", "1.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.chefe.fornalha";

		internal static Plugin Instance;

		internal static readonly Vector3 Position = new Vector3(-17f, 255f, 1874.7f);

		private FurnaceModel _model;

		private byte[] _texture;

		private byte[] _normal;

		private GameObject _actor;

		private Character _body;

		private SL_Character _template;

		private bool _creating;

		private bool _visited;

		private int _generation;

		private float _nextAttempt;

		private float _warning;

		private ConfigEntry<KeyboardShortcut> _reset;

		private ConfigEntry<bool> _detailed;

		private static readonly ArenaPlayerCandidates Candidates = new ArenaPlayerCandidates();

		internal bool Detailed
		{
			get
			{
				if (_detailed != null)
				{
					return _detailed.Value;
				}
				return false;
			}
		}

		public static event Action<Character> BossDefeated;

		internal static void ReportVictory(Character body)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Instance?.Message("DERROTADO uid=" + UID.op_Implicit(body.UID) + ";vida=" + body.Stats.CurrentHealth);
			Action<Character> bossDefeated = Plugin.BossDefeated;
			if (bossDefeated == null)
			{
				return;
			}
			Delegate[] invocationList = bossDefeated.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<Character> action = (Action<Character>)invocationList[i];
				try
				{
					action(body);
				}
				catch (Exception ex)
				{
					Plugin instance = Instance;
					if (instance != null)
					{
						((BaseUnityPlugin)instance).Logger.LogError((object)("[Fornalha] Observador de missao: " + ex));
					}
				}
			}
		}

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_detailed = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostico", "Detalhado", false, "Registra cada golpe/estado; desligado reduz escrita de log. Spawn e erros sempre registrados.");
			_reset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Teste", "Recriar", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Recria SOMENTE o chefe ate40m do centro. F10 continua sendo das torretas.");
			try
			{
				string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets");
				_model = FurnaceModel.Load(Path.Combine(path, "furnace.rig"));
				_texture = File.ReadAllBytes(Path.Combine(path, "carapace.png"));
				_normal = File.ReadAllBytes(Path.Combine(path, "carapace_normal.png"));
				Message("1.1.2;sinal de morte real para missao;perseguicao3m/s,furia4m/s,contatos mais rapidos,recuperacao1s;carapaca1K,8combos+2furia;Beetle Golem externo CC-BY-SA3.0;" + _model.Names.Length + "ossos/" + _model.Vertices.Length + "vertices/" + _model.Triangles.Length / 3 + "triangulos/6clips;import direto sem Unity Editor.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[Fornalha] FALHA de asset:" + ex));
				((Behaviour)this).enabled = false;
				return;
			}
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += SceneLoaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
		}

		private void Prepare()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result

BepInEx/plugins/Codex_Cidade_Postes/CodexCidadePostes.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCidadePostes
{
	[BepInPlugin("codex.outward.cidade.postes", "Codex - Postes Noturnos da Cidade", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class District
		{
			internal readonly bool Fenda;

			internal readonly string Name;

			internal readonly float X;

			internal readonly float Z;

			internal readonly float Range;

			internal readonly float Intensity;

			internal readonly float[,] Locations;

			internal readonly Light[] Lights;

			internal readonly Collider[] Supports;

			internal List<Character> Players = new List<Character>();

			internal GameObject Root;

			internal float NextAttempt;

			internal District(string name, bool fenda, float x, float z, float[,] locations)
			{
				Name = name;
				Fenda = fenda;
				X = x;
				Z = z;
				Range = (fenda ? 30f : 46f);
				Intensity = (fenda ? 2.8f : 4.4f);
				Locations = locations;
				Lights = (Light[])(object)new Light[locations.GetLength(0)];
				Supports = (Collider[])(object)new Collider[Lights.Length];
			}
		}

		private readonly District[] _districts = new District[3]
		{
			new District("Central", fenda: false, 0f, 0f, StreetDesign.Locations),
			new District("Fenda", fenda: true, -850f, -76f, StreetDesign.FendaLocations),
			new District("ValeManso", fenda: true, -450f, 45f, StreetDesign.VillageLocations)
		};

		private GameObject _root;

		private StreetResources _resources;

		private ConfigEntry<bool> _always;

		private float _nextTick;

		private float _lastTick;

		private float _level;

		private float _nextClockWarning;

		private bool _clockKnown;

		private bool? _lastNight;

		private void Awake()
		{
			_always = ((BaseUnityPlugin)this).Config.Bind<bool>("Luzes", "SempreAcesas", false, "Se true, ignora horario apenas nos postes; o sol da arena continua independente.");
			SceneManager.sceneLoaded += SceneLoaded;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[CidadePostes] 1.3.0;8centrais range46m/int4.4;8Fenda+6ValeManso range30m/int2.8;noite nativa TOD_Sky.IsNight;sol intacto.");
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
				_nextTick = 0f;
				_clockKnown = false;
				_lastNight = null;
			}
		}

		private void Update()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < _nextTick)
			{
				return;
			}
			float seconds = Mathf.Min(0.5f, Mathf.Max(0f, unscaledTime - _lastTick));
			_lastTick = unscaledTime;
			_nextTick = unscaledTime + 0.25f;
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name != "CierzoTutorial")
			{
				Cleanup();
				return;
			}
			bool flag = false;
			District[] districts = _districts;
			foreach (District district in districts)
			{
				bool flag2 = HasViewer(district, name);
				flag = flag || flag2;
				if (flag2 && unscaledTime >= district.NextAttempt)
				{
					district.NextAttempt = unscaledTime + 10f;
					try
					{
						for (int j = 0; j < district.Lights.Length; j++)
						{
							if ((Object)(object)district.Lights[j] != (Object)null && (Object)(object)district.Supports[j] == (Object)null)
							{
								Cleanup();
								return;
							}
							if ((Object)(object)district.Lights[j] == (Object)null)
							{
								TryPost(district, j);
							}
						}
					}
					catch (Exception ex)
					{
						Cleanup();
						((BaseUnityPlugin)this).Logger.LogError((object)("[CidadePostes] Erro isolado,cenario preservado: " + ex));
						return;
					}
				}
				if ((Object)(object)district.Root != (Object)null && district.Root.activeSelf != flag2)
				{
					district.Root.SetActive(flag2);
				}
			}
			TOD_Sky instance = TOD_Sky.Instance;
			if (_always.Value || ((Object)(object)instance != (Object)null && instance.Initialized))
			{
				bool flag3 = _always.Value || instance.IsNight;
				if (!_clockKnown)
				{
					_level = (flag3 ? 1 : 0);
					_clockKnown = true;
				}
				else
				{
					_level = StreetDesign.Fade(_level, flag3, seconds);
				}
				if (_lastNight != flag3)
				{
					_lastNight = flag3;
					((BaseUnityPlugin)this).Logger.LogMessage((object)("[CidadePostes] " + (flag3 ? "Acendendo" : "Apagando") + ";fonte=" + (_always.Value ? "configSempre" : "TOD_Sky.IsNight") + ";hora=" + (((Object)(object)instance != (Object)null && instance.Cycle != null) ? instance.Cycle.Hour.ToString("F2") : "indisponivel")));
				}
			}
			else if (flag && unscaledTime >= _nextClockWarning)
			{
				_nextClockWarning = unscaledTime + 30f;
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[CidadePostes] Aguardando ceu/relogio nativo;estado anterior preservado.");
			}
			if ((Object)(object)_resources == (Object)null)
			{
				return;
			}
			_resources.SetNight(_level);
			districts = _districts;
			foreach (District district2 in districts)
			{
				bool flag4 = (Object)(object)district2.Root != (Object)null && district2.Root.activeSelf;
				Light[] lights = district2.Lights;
				foreach (Light val in lights)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.intensity = district2.Intensity * _level;
						((Behaviour)val).enabled = flag4 && _level > 0.001f && NearViewer(district2, ((Component)val).transform.position, 110f);
					}
				}
			}
		}

		private bool HasViewer(District district, string scene)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			district.Players.Clear();
			CharacterManager instance = CharacterManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			instance.FindCharactersInRange(new Vector3(1783f + district.X, 255f, 1796.7f + district.Z), 260f, ref district.Players);
			foreach (Character player in district.Players)
			{
				if ((Object)(object)player != (Object)null && StreetDesign.Visible(scene, player.IsLocalPlayer, ((Component)player).transform.position.x, ((Component)player).transform.position.y, ((Component)player).transform.position.z, district.X, district.Z))
				{
					return true;
				}
			}
			return false;
		}

		private static bool NearViewer(District district, Vector3 point, float range)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Character player in district.Players)
			{
				if ((Object)(object)player != (Object)null && player.IsLocalPlayer && ((Component)player).transform.position.y > 220f)
				{
					Vector3 val = ((Component)player).transform.position - point;
					if (((Vector3)(ref val)).sqrMagnitude <= range * range)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool Floor(District district, Vector3 point, out RaycastHit hit)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			hit = default(RaycastHit);
			bool flag = false;
			point.y = 280f;
			RaycastHit[] array = Physics.RaycastAll(new Ray(point, Vector3.down), 60f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!((Object)(object)collider == (Object)null) && collider.enabled && !collider.isTrigger && StreetDesign.IsSupport(((Object)collider).name, district.Fenda) && !(((RaycastHit)(ref val)).point.y <= 220f) && !(((RaycastHit)(ref val)).normal.y < 0.8f) && (!flag || ((RaycastHit)(ref val)).point.y > ((RaycastHit)(ref hit)).point.y))
				{
					hit = val;
					flag = true;
				}
			}
			return flag;
		}

		private void EnsureRoot(District district, Collider floor)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			if ((Object)(object)_root == (Object)null)
			{
				_root = new GameObject("Codex_Cidade_Postes_Noturnos");
				SceneManager.MoveGameObjectToScene(_root, ((Component)floor).gameObject.scene);
				_resources = _root.AddComponent<StreetResources>();
				_resources.Load();
			}
			if (!((Object)(object)district.Root != (Object)null))
			{
				district.Root = new GameObject("Postes_" + district.Name);
				district.Root.transform.SetParent(_root.transform, false);
				district.Root.SetActive(false);
			}
		}

		private void TryPost(District district, int index)
		{
			//IL_005d: 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)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			float num = district.Locations[index, 0];
			float num2 = district.Locations[index, 1];
			Vector3 point = default(Vector3);
			((Vector3)(ref point))..ctor(1783f + district.X + num, 280f, 1796.7f + district.Z + num2);
			string text = district.Name + ":" + index;
			if (!Floor(district, point, out var hit))
			{
				((BaseUnityPlugin)this).Logger.LogMessage((object)("[CidadePostes:" + text + "] Aguardando piso autorizado."));
				return;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				Vector3.forward,
				Vector3.back,
				Vector3.left,
				Vector3.right
			};
			foreach (Vector3 val in array)
			{
				if (!Floor(district, ((RaycastHit)(ref hit)).point + val * 0.35f, out var hit2) || Mathf.Abs(((RaycastHit)(ref hit2)).point.y - ((RaycastHit)(ref hit)).point.y) > 0.2f)
				{
					((BaseUnityPlugin)this).Logger.LogMessage((object)("[CidadePostes:" + text + "] Apoio irregular;omitido."));
					return;
				}
			}
			Collider[] array2 = Physics.OverlapBox(((RaycastHit)(ref hit)).point + Vector3.up * 2.15f, new Vector3(1.2f, 2.1f, 1.2f), Quaternion.identity, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && !StreetDesign.IsSupport(((Object)val2).name, district.Fenda))
				{
					((BaseUnityPlugin)this).Logger.LogMessage((object)("[CidadePostes:" + text + "] Lote ocupado por " + ((Object)val2).name + ",cenario preservado."));
					return;
				}
			}
			EnsureRoot(district, ((RaycastHit)(ref hit)).collider);
			GameObject val3 = new GameObject("CidadePoste_" + text);
			val3.transform.SetParent(district.Root.transform, false);
			val3.transform.position = ((RaycastHit)(ref hit)).point;
			val3.transform.rotation = Quaternion.Euler(0f, Mathf.Atan2(num, num2) * 57.29578f, 0f);
			val3.layer = ((Component)((RaycastHit)(ref hit)).collider).gameObject.layer;
			try
			{
				_resources.Part(val3, "Ferro_Torneado", _resources.Stand, _resources.Iron);
				_resources.Part(val3, "Lanterna_CodeInferno_CC0", _resources.Lantern, _resources.Lamp, solid: true);
				CapsuleCollider obj = val3.AddComponent<CapsuleCollider>();
				obj.radius = 0.3f;
				obj.height = 3.8f;
				obj.center = new Vector3(0f, 1.82f, 0.08f);
				NavMeshObstacle obj2 = val3.AddComponent<NavMeshObstacle>();
				obj2.shape = (NavMeshObstacleShape)0;
				obj2.radius = 0.35f;
				obj2.height = 4.1f;
				obj2.center = new Vector3(0f, 2f, 0.08f);
				obj2.carving = true;
				obj2.carveOnlyStationary = true;
				GameObject val4 = new GameObject("Luz_Quente");
				val4.transform.SetParent(val3.transform, false);
				val4.transform.localPosition = new Vector3(0f, 3.35f, -0.65f);
				Light val5 = val4.AddComponent<Light>();
				val5.type = (LightType)2;
				val5.color = new Color(1f, 0.76f, 0.43f);
				val5.range = district.Range;
				val5.intensity = 0f;
				((Behaviour)val5).enabled = false;
				val5.shadows = (LightShadows)0;
				val5.renderMode = (LightRenderMode)1;
				district.Lights[index] = val5;
				district.Supports[index] = ((RaycastHit)(ref hit)).collider;
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj3 = new string[13]
				{
					"[CidadePostes:",
					text,
					"] PRONTO;local=",
					(district.X + num).ToString(),
					",",
					(district.Z + num2).ToString(),
					";pisoY=",
					((RaycastHit)(ref hit)).point.y.ToString(),
					";solid/navCarve;range",
					null,
					null,
					null,
					null
				};
				float range = district.Range;
				obj3[9] = range.ToString();
				obj3[10] = "m/int";
				range = district.Intensity;
				obj3[11] = range.ToString();
				obj3[12] = ".";
				logger.LogMessage((object)string.Concat(obj3));
			}
			catch
			{
				val3.SetActive(false);
				Object.Destroy((Object)(object)val3);
				throw;
			}
		}

		private void Cleanup()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
				if ((Object)(object)_resources != (Object)null)
				{
					_resources.ReleaseAssets();
				}
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_resources = null;
			District[] districts = _districts;
			foreach (District district in districts)
			{
				district.Root = null;
				district.NextAttempt = 0f;
				district.Players.Clear();
				Array.Clear(district.Lights, 0, district.Lights.Length);
				Array.Clear(district.Supports, 0, district.Supports.Length);
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= SceneLoaded;
			Cleanup();
		}
	}
	internal static class StreetDesign
	{
		internal const float RoomX = 1783f;

		internal const float RoomZ = 1796.7f;

		internal const float MinimumY = 220f;

		internal const float ViewRange = 230f;

		internal const float EnvelopeRadius = 1.2f;

		internal const float Height = 4.1f;

		internal const float LightRange = 30f;

		internal const float Intensity = 2.8f;

		internal const float FadeSeconds = 2f;

		internal const float FendaX = -850f;

		internal const float FendaZ = -76f;

		internal const float LightViewRange = 110f;

		internal const float VillageX = -450f;

		internal const float VillageZ = 45f;

		internal const float CentralLightRange = 46f;

		internal const float CentralIntensity = 4.4f;

		internal static readonly float[,] Locations = new float[8, 2]
		{
			{ -42f, -47f },
			{ 10f, -44f },
			{ 43f, -47f },
			{ -50f, 8f },
			{ 50f, 8f },
			{ -40f, 47f },
			{ 0f, 48f },
			{ 40f, 47f }
		};

		internal static readonly float[,] FendaLocations = new float[8, 2]
		{
			{ -5f, -9f },
			{ -12f, 5f },
			{ 24f, -26f },
			{ 17f, 37f },
			{ -19f, 33f },
			{ -28f, 1f },
			{ 41f, -17f },
			{ -8f, 55f }
		};

		internal static readonly float[,] VillageLocations = new float[6, 2]
		{
			{ -5f, -20f },
			{ 5f, -11f },
			{ -29f, -1f },
			{ -15f, 26f },
			{ 29f, 8f },
			{ 5f, 27f }
		};

		internal static bool IsSupport(string name, bool fenda)
		{
			if (name != null)
			{
				if (!fenda)
				{
					return name == "Piso_Principal_Colisor";
				}
				return name.StartsWith("Campo_Oeste_Setor_", StringComparison.Ordinal);
			}
			return false;
		}

		internal static bool Visible(string scene, bool local, float x, float y, float z, float offsetX = 0f, float offsetZ = 0f)
		{
			double num = x - 1783f - offsetX;
			double num2 = z - 1796.7f - offsetZ;
			if (scene == "CierzoTutorial" && local && y > 220f)
			{
				return num * num + num2 * num2 <= 52900.0;
			}
			return false;
		}

		internal static float Fade(float current, bool night, float seconds)
		{
			if (float.IsNaN(seconds) || float.IsInfinity(seconds) || seconds < 0f)
			{
				seconds = 0f;
			}
			if (float.IsNaN(current) || float.IsInfinity(current))
			{
				current = 0f;
			}
			current = Math.Max(0f, Math.Min(1f, current));
			float num = seconds / 2f;
			if (!night)
			{
				return Math.Max(0f, current - num);
			}
			return Math.Min(1f, current + num);
		}

		internal static bool Window(float r, float g, float b)
		{
			if (r > 0.5f && g > 0.35f && b < g * 0.85f)
			{
				return r > g * 0.95f;
			}
			return false;
		}
	}
	internal sealed class StreetResources : MonoBehaviour
	{
		internal Mesh Lantern;

		internal Mesh Stand;

		internal Material Lamp;

		internal Material Iron;

		private readonly List<Object> _owned = new List<Object>();

		private float _lastLevel = -1f;

		internal void Load()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Expected O, but got Unknown
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "Assets");
			Lantern = ReadMesh(Path.Combine(path, "lantern.mesh"));
			Stand = Lathe();
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Shader Standard ausente.");
			}
			Texture2D val2 = Own<Texture2D>(new Texture2D(2, 2, (TextureFormat)4, true));
			if (!ImageConversion.LoadImage(val2, File.ReadAllBytes(Path.Combine(path, "lanterntex.png")), false) || ((Texture)val2).width > 1024 || ((Texture)val2).height > 1024)
			{
				throw new InvalidDataException("Atlas da lanterna invalido/maior que1K.");
			}
			Color[] pixels = val2.GetPixels();
			Color[] array = (Color[])(object)new Color[pixels.Length];
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val3 = pixels[i];
				if (StreetDesign.Window(val3.r, val3.g, val3.b))
				{
					array[i] = val3;
					pixels[i] = new Color(0.18f, 0.19f, 0.17f, 1f);
				}
				else
				{
					array[i] = Color.black;
				}
			}
			Texture2D val4 = Own<Texture2D>(new Texture2D(((Texture)val2).width, ((Texture)val2).height, (TextureFormat)4, true));
			val4.SetPixels(array);
			val4.Apply(true, true);
			val2.SetPixels(pixels);
			val2.Apply(true, true);
			((Texture)val2).filterMode = (FilterMode)2;
			((Texture)val2).anisoLevel = 2;
			((Texture)val4).filterMode = (FilterMode)2;
			Lamp = Own<Material>(new Material(val));
			((Object)Lamp).name = "CidadePostes_Ferro_Vidro_Noite";
			Lamp.color = Color.white;
			Lamp.mainTexture = (Texture)(object)val2;
			Lamp.SetFloat("_Metallic", 0.25f);
			Lamp.SetFloat("_Glossiness", 0.28f);
			Lamp.SetTexture("_EmissionMap", (Texture)(object)val4);
			Lamp.EnableKeyword("_EMISSION");
			Iron = Own<Material>(new Material(val));
			((Object)Iron).name = "CidadePostes_Ferro_Torneado";
			Iron.color = new Color(0.23f, 0.25f, 0.24f);
			Iron.SetFloat("_Metallic", 0.6f);
			Iron.SetFloat("_Glossiness", 0.28f);
			SetNight(0f);
		}

		internal void SetNight(float level)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!(Mathf.Abs(_lastLevel - level) < 0.0001f))
			{
				_lastLevel = level;
				Lamp.SetColor("_EmissionColor", new Color(2.5f * level, 2.1f * level, 1.45f * level));
			}
		}

		private Mesh ReadMesh(string path)
		{
			//IL_00c3: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "CLAMP001")
			{
				throw new InvalidDataException("Header da malha invalido.");
			}
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			if (num < 3 || num > 30000 || num2 < 3 || num2 > 60000 || num2 % 3 != 0 || binaryReader.BaseStream.Length != 16 + (long)num * 32L + (long)num2 * 4L)
			{
				throw new InvalidDataException("Dimensoes da malha invalidas.");
			}
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			int[] array4 = new int[num2];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array2[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array3[i] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				if (!Finite(array[i].x) || !Finite(array[i].y) || !Finite(array[i].z) || !Finite(array2[i].x) || !Finite(array2[i].y) || !Finite(array2[i].z) || !Finite(array3[i].x) || !Finite(array3[i].y))
				{
					throw new InvalidDataException("Vertice nao finito.");
				}
			}
			for (int j = 0; j < num2; j++)
			{
				array4[j] = binaryReader.ReadInt32();
				if (array4[j] < 0 || array4[j] >= num)
				{
					throw new InvalidDataException("Indice invalido.");
				}
			}
			Mesh obj = Own<Mesh>(new Mesh());
			((Object)obj).name = "CodeInferno_Lanterna144tri";
			obj.vertices = array;
			obj.normals = array2;
			obj.uv = array3;
			obj.triangles = array4;
			obj.RecalculateTangents();
			obj.RecalculateBounds();
			return obj;
		}

		private static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		private Mesh Lathe()
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			float[,] array = new float[16, 2]
			{
				{ -0.08f, 0.25f },
				{ 0f, 0.25f },
				{ 0.1f, 0.3f },
				{ 0.2f, 0.3f },
				{ 0.3f, 0.17f },
				{ 0.4f, 0.13f },
				{ 0.5f, 0.15f },
				{ 0.56f, 0.11f },
				{ 2.5f, 0.1f },
				{ 2.55f, 0.15f },
				{ 2.65f, 0.15f },
				{ 2.7f, 0.1f },
				{ 3.5f, 0.1f },
				{ 3.65f, 0.15f },
				{ 3.72f, 0.13f },
				{ 3.77f, 0f }
			};
			int length = array.GetLength(0);
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			for (int i = 0; i < length; i++)
			{
				for (int j = 0; j <= 20; j++)
				{
					float num = (float)j * (float)Math.PI * 2f / 20f;
					list.Add(new Vector3(Mathf.Sin(num) * array[i, 1], array[i, 0], Mathf.Cos(num) * array[i, 1] + 0.08f));
					list2.Add(new Vector2((float)j / 20f, array[i, 0]));
					if (i != 0 && j != 20)
					{
						int num2 = (i - 1) * 21 + j;
						int item = num2 + 1;
						int num3 = i * 21 + j;
						int item2 = num3 + 1;
						list3.Add(num2);
						list3.Add(item);
						list3.Add(num3);
						if (array[i, 1] > 0f)
						{
							list3.Add(item);
							list3.Add(item2);
							list3.Add(num3);
						}
					}
				}
			}
			int count = list.Count;
			list.Add(new Vector3(0f, array[0, 0], 0.08f));
			list2.Add(Vector2.zero);
			for (int k = 0; k < 20; k++)
			{
				list3.Add(count);
				list3.Add(k + 1);
				list3.Add(k);
			}
			Mesh obj = Own<Mesh>(new Mesh());
			((Object)obj).name = "CidadePoste_Ferro20Lados";
			obj.SetVertices(list);
			obj.SetUVs(0, list2);
			obj.SetTriangles(list3, 0);
			obj.RecalculateNormals();
			obj.RecalculateBounds();
			return obj;
		}

		internal void Part(GameObject parent, string name, Mesh mesh, Material material, bool solid = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			val.layer = parent.layer;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			if (solid)
			{
				val.AddComponent<MeshCollider>().sharedMesh = mesh;
			}
		}

		private T Own<T>(T asset) where T : Object
		{
			_owned.Add((Object)(object)asset);
			return asset;
		}

		internal void ReleaseAssets()
		{
			foreach (Object item in _owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			_owned.Clear();
		}

		private void OnDestroy()
		{
			ReleaseAssets();
		}
	}
}

BepInEx/plugins/Codex_Cidade_Viva/CodexCidadeViva.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCidadeViva
{
	internal sealed class CourierWalking
	{
		private readonly Character body;

		private readonly CharacterController motor;

		private readonly float[,] stops = TownPlan.Residents[3].Stops;

		private int stop;

		private int direction = 1;

		private int destination;

		private Vector3[] path;

		private int corner;

		private float waitUntil;

		private float nextTry;

		private float nextWarning;

		private float vertical = -2f;

		internal CourierWalking(Character body, CharacterController motor)
		{
			this.body = body;
			this.motor = motor;
			waitUntil = Time.time + 4f;
		}

		internal void Tick()
		{
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: 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_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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: 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_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: 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_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < waitUntil)
			{
				body.SetAnimMove(0f, 0f);
				return;
			}
			if (path == null)
			{
				if (Time.unscaledTime < nextTry)
				{
					body.SetAnimMove(0f, 0f);
					return;
				}
				nextTry = Time.unscaledTime + 4f;
				int num = direction;
				destination = TownPlan.CourierNext(stop, ref num);
				Vector3 val = Plugin.World(stops[destination, 0], stops[destination, 1]);
				Vector3 position = ((Component)body).transform.position;
				Vector3 val2 = val - position;
				val2.y = 0f;
				int num2 = Mathf.Max(1, Mathf.CeilToInt(((Vector3)(ref val2)).magnitude / 2f));
				Vector3[] array = (Vector3[])(object)new Vector3[num2];
				bool flag = true;
				float num3 = position.y - 0.12f;
				for (int i = 0; i < num2; i++)
				{
					Vector3 val3 = Vector3.Lerp(position, val, ((float)i + 1f) / (float)num2);
					if (!TownPlan.PathPointAllowed(3, val3.x - 1783f, val3.z - 1796.7f) || !WorldGround.Try(val3, out var floor, out var support) || Mathf.Abs(floor.y - num3) > 0.55f || !Plugin.ClearBody(floor, support, body))
					{
						flag = false;
						break;
					}
					array[i] = floor + Vector3.up * 0.12f;
					num3 = floor.y;
				}
				if (!flag)
				{
					WaitForPath();
					return;
				}
				direction = num;
				path = array;
				corner = 0;
				Plugin.Instance.Log("CAIO TRECHO " + stop + "->" + destination + ";sentido=" + ((direction > 0) ? "Vale Manso" : "cidade") + ";apoio real/sem teleportes.");
			}
			Vector3 position2 = ((Component)body).transform.position;
			Vector3 val4 = path[corner] - position2;
			val4.y = 0f;
			if (((Vector3)(ref val4)).sqrMagnitude < 0.16f)
			{
				corner++;
				if (corner == path.Length)
				{
					stop = destination;
					path = null;
					waitUntil = Time.time + ((stop == 0 || stop == stops.GetLength(0) - 1) ? 18f : 0.15f);
					body.SetAnimMove(0f, 0f);
					if (stop == 0 || stop == stops.GetLength(0) - 1)
					{
						Plugin.Instance.Log("CAIO CHEGOU " + ((stop == 0) ? "cidade" : "Vale Manso") + ";pausa18s.");
					}
					return;
				}
				val4 = path[corner] - position2;
				val4.y = 0f;
			}
			float num4 = Mathf.Min(Time.deltaTime, 0.05f);
			if (num4 <= 0f)
			{
				return;
			}
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			if (!WorldGround.Try(position2 + normalized * 0.8f, out var floor2, out var support2) || !Plugin.ClearBody(floor2, support2, body))
			{
				path = null;
				waitUntil = Time.time + 3f;
				WaitForPath();
				return;
			}
			((Component)body).transform.rotation = Quaternion.RotateTowards(((Component)body).transform.rotation, Quaternion.LookRotation(normalized), 180f * num4);
			vertical = (motor.isGrounded ? (-2f) : Mathf.Max(-12f, vertical - 18f * num4));
			motor.Move((normalized * Mathf.Min(2.2f, ((Vector3)(ref val4)).magnitude / num4) + Vector3.up * vertical) * num4);
			Vector3 val5 = ((Component)body).transform.position - position2;
			val5.y = 0f;
			body.SetAnimMove(0f, Mathf.Min(1.4f, ((Vector3)(ref val5)).magnitude / num4));
			if (((Vector3)(ref val5)).magnitude < num4 * 0.08f)
			{
				path = null;
				waitUntil = Time.time + 3f;
				WaitForPath();
			}
		}

		private void WaitForPath()
		{
			body.SetAnimMove(0f, 0f);
			if (!(Time.unscaledTime < nextWarning))
			{
				nextWarning = Time.unscaledTime + 25f;
				Plugin.Instance.Log("CAIO AGUARDANDO trecho " + stop + "->" + destination + ";piso/espaco ainda indisponível;nao pula etapas.");
			}
		}
	}
	internal sealed class FindLot
	{
		internal readonly string Key;

		internal readonly string Name;

		internal readonly int ItemId;

		internal readonly float X;

		internal readonly float Z;

		internal FindLot(string key, string name, int id, float x, float z)
		{
			Key = "codex.finds.v1." + key;
			Name = name;
			ItemId = id;
			X = x;
			Z = z;
		}
	}
	internal static class FindsPlan
	{
		internal static readonly FindLot[] Lots = new FindLot[7]
		{
			new FindLot("brejo.robe", "Jade-Lich Robes", 3000040, -1529f, -94f),
			new FindLot("brejo.mask", "Jade-Lich Mask", 3000041, -1487f, -94f),
			new FindLot("brejo.boots", "Jade-Lich Boots", 3000043, -1510f, -77f),
			new FindLot("brejo.weapon", "wodd", 9000011, -1505f, -116f),
			new FindLot("arena.geluzia", "Geluzia", 9000006, -1800f, 100f),
			new FindLot("neve.boots", "Crimson Plate Boots", 3100092, -80f, 17f),
			new FindLot("vale.mask", "Gold-Lich Mask", 3000211, -400f, 55f)
		};
	}
	[BepInPlugin("codex.outward.cidade.viva", "Codex - Vida nas Muralhas", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal TownLandmarks Landmarks;

		private const int ActiveResidentCount = 4;

		private readonly SL_Character[] templates = (SL_Character[])(object)new SL_Character[4];

		private readonly Character[] bodies = (Character[])(object)new Character[4];

		private readonly bool[] ready = new bool[4];

		private readonly float[] retry = new float[4];

		private readonly WorldFinds finds = new WorldFinds();

		private List<Character> players = new List<Character>();

		private float nextScan;

		private float nextBuild;

		private bool creating;

		private int generation;

		internal bool Gameplay { get; private set; }

		internal bool Night
		{
			get
			{
				if ((Object)(object)TOD_Sky.Instance != (Object)null && TOD_Sky.Instance.Initialized)
				{
					return TOD_Sky.Instance.IsNight;
				}
				return false;
			}
		}

		private void Awake()
		{
			Instance = this;
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += Loaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			Log("1.1.1;moradores e dialogos locais;perfil Deck limitado quando compilado para teste.");
		}

		private void Prepare()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			for (int i = 0; i < templates.Length; i++)
			{
				if (templates[i] == null)
				{
					ResidentPlan residentPlan = TownPlan.Residents[i];
					SL_Character val = new SL_Character
					{
						UID = residentPlan.Uid,
						Name = residentPlan.Name,
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						DestroyOnDeath = false,
						Faction = (Factions)0,
						Health = 500f,
						HealthRegen = 0f,
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = residentPlan.Chest,
						Boots_ID = residentPlan.Boots,
						Backpack_ID = -1,
						CharacterVisualsData = new VisualData
						{
							Gender = (Gender)(residentPlan.Female ? 1 : 0),
							SkinIndex = ((i == 3) ? 2 : (1 + i)),
							HeadVariationIndex = ((i == 3) ? 4 : (2 + i)),
							HairStyleIndex = (residentPlan.Female ? 8 : 3),
							HairColorIndex = ((i == 3) ? 6 : (6 + i))
						},
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false,
						AutoTeleportWhenFar = false
					};
					((ContentTemplate)val).ApplyTemplate();
					templates[i] = val;
				}
			}
		}

		private void Loaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
			}
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			Scene activeScene = SceneManager.GetActiveScene();
			Gameplay = ((Scene)(ref activeScene)).name == "CierzoTutorial" && (Object)(object)instance != (Object)null && instance.IsOverallLoadingDone && !instance.IsGameplayPaused;
			if (Time.unscaledTime < nextScan)
			{
				return;
			}
			nextScan = Time.unscaledTime + 0.4f;
			players.Clear();
			if ((Object)(object)CharacterManager.Instance != (Object)null)
			{
				CharacterManager.Instance.FindCharactersInRange(new Vector3(1783f, 255f, 1796.7f), 650f, ref players);
			}
			if ((Object)(object)Landmarks != (Object)null)
			{
				Landmarks.Show(DistanceSquared(new Vector3(1783f, 255f, 1796.7f)) < 52900f);
			}
			if (!Gameplay || PhotonNetwork.isNonMasterClientInRoom || DistanceSquared(new Vector3(1783f, 255f, 1796.7f)) > 19600f)
			{
				return;
			}
			if ((Object)(object)Landmarks == (Object)null && Time.unscaledTime >= nextBuild)
			{
				nextBuild = Time.unscaledTime + 8f;
				try
				{
					Landmarks = TownLandmarks.Build();
					if ((Object)(object)Landmarks != (Object)null)
					{
						Log("MARCOS PRONTOS:mercado/praça/entrada/sede;colisões locais,sem trocar piso.");
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)ex);
				}
			}
			if (creating)
			{
				return;
			}
			for (int i = 0; i < templates.Length; i++)
			{
				if (ready[i] || templates[i] == null || !(Time.unscaledTime >= retry[i]))
				{
					continue;
				}
				ResidentPlan residentPlan = TownPlan.Residents[i];
				if (!Surface(World(residentPlan.Stops[0, 0], residentPlan.Stops[0, 1]), out var floor, out var support))
				{
					retry[i] = Time.unscaledTime + 3f;
					continue;
				}
				if (!ClearBody(floor, support, null))
				{
					retry[i] = Time.unscaledTime + 5f;
					continue;
				}
				((MonoBehaviour)this).StartCoroutine(Create(i, floor, generation));
				break;
			}
		}

		private IEnumerator Create(int slot, Vector3 floor, int token)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			creating = true;
			try
			{
				bodies[slot] = templates[slot].Spawn(floor + Vector3.up * 0.12f, (string)null, (string)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			Character body = bodies[slot];
			float deadline = Time.unscaledTime + 25f;
			while ((Object)(object)body != (Object)null && token == generation && (!body.Initialized || (Object)(object)body.Animator == (Object)null || (Object)(object)((Component)body).GetComponentInChildren<CharacterVisuals>(true) == (Object)null) && Time.unscaledTime < deadline)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (token != generation)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)body == (Object)null || !body.Initialized || (Object)(object)body.Animator == (Object)null || (Object)(object)((Component)body).GetComponentInChildren<CharacterVisuals>(true) == (Object)null)
				{
					throw new InvalidOperationException("Morador ainda incompleto");
				}
				if (!Surface(floor, out var floor2, out var support) || !ClearBody(floor2, support, body))
				{
					throw new InvalidOperationException("Apoio/lote ainda ocupado");
				}
				Vector3 val = floor2 + Vector3.up * 0.12f;
				int num;
				switch (slot)
				{
				default:
					num = 135;
					break;
				case 0:
					num = 180;
					break;
				case 1:
				case 3:
					num = 90;
					break;
				}
				body.Teleport(val, Quaternion.Euler(0f, (float)num, 0f));
				body.Invincible = true;
				CharacterVisuals componentInChildren = ((Component)body).GetComponentInChildren<CharacterVisuals>(true);
				if ((Object)(object)((Component)componentInChildren).transform != (Object)(object)((Component)body).transform)
				{
					Transform transform = ((Component)componentInChildren).transform;
					transform.localPosition += Vector3.up * 0.08f;
				}
				ResidentRoutine residentRoutine = ((Component)body).gameObject.AddComponent<ResidentRoutine>();
				residentRoutine.Setup(body, slot);
				if (!TownDialogue.Attach(body, residentRoutine))
				{
					throw new InvalidOperationException("TrainerTemplate/dialogo indisponível");
				}
				ready[slot] = true;
				Log("NPC PRONTO " + TownPlan.Residents[slot].Name + ";uid=" + UID.op_Implicit(body.UID) + ";piso=" + ((Object)support).name + ";dialogo nativo/rotina curta.");
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[CidadeViva]Morador aguardando:" + ex2));
				if ((Object)(object)body != (Object)null)
				{
					CustomCharacters.DestroyCharacterRPC(body);
				}
				bodies[slot] = null;
				retry[slot] = Time.unscaledTime + 10f;
			}
			creating = false;
		}

		internal static Vector3 World(float x, float z)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(1783f + x, 255f, 1796.7f + z);
		}

		internal static bool Surface(Vector3 guess, out Vector3 floor, out Collider support)
		{
			//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_0048: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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)
			floor = guess;
			support = null;
			GameObject val = GameObject.Find("Piso_Principal_Colisor");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Collider component = val.GetComponent<Collider>();
			if ((Object)(object)component == (Object)null || !component.enabled || !((Component)component).gameObject.activeInHierarchy)
			{
				return false;
			}
			RaycastHit val2 = default(RaycastHit);
			if (!component.Raycast(new Ray(new Vector3(guess.x, 280f, guess.z), Vector3.down), ref val2, 60f) || ((RaycastHit)(ref val2)).point.y < 220f || ((RaycastHit)(ref val2)).normal.y < 0.8f)
			{
				return false;
			}
			floor = ((RaycastHit)(ref val2)).point;
			support = component;
			return true;
		}

		internal static bool ClearBody(Vector3 at, Collider floor, Character self)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapCapsule(at + Vector3.up * 0.75f, at + Vector3.up * 1.7f, 0.42f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)floor && ((Object)(object)self == (Object)null || (Object)(object)((Component)val).GetComponentInParent<Character>() != (Object)(object)self))
				{
					return false;
				}
			}
			return true;
		}

		internal float DistanceSquared(Vector3 at)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			float num = float.PositiveInfinity;
			foreach (Character player in players)
			{
				if ((Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && ((Component)player).transform.position.y > 220f)
				{
					float num2 = num;
					Vector3 val = ((Component)player).transform.position - at;
					num = Mathf.Min(num2, ((Vector3)(ref val)).sqrMagnitude);
				}
			}
			return num;
		}

		internal ResidentRoutine Resident(int role)
		{
			if (role < 0 || role >= bodies.Length || !((Object)(object)bodies[role] != (Object)null))
			{
				return null;
			}
			return ((Component)bodies[role]).GetComponent<ResidentRoutine>();
		}

		internal void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[CidadeViva]" + message));
		}

		private void Cleanup()
		{
			generation++;
			((MonoBehaviour)this).StopAllCoroutines();
			creating = false;
			for (int i = 0; i < bodies.Length; i++)
			{
				if ((Object)(object)bodies[i] != (Object)null)
				{
					CustomCharacters.DestroyCharacterRPC(bodies[i]);
				}
				bodies[i] = null;
				ready[i] = false;
				retry[i] = 0f;
			}
			if ((Object)(object)Landmarks != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Landmarks).gameObject);
			}
			Landmarks = null;
			players.Clear();
			finds.Reset();
			nextBuild = (nextScan = 0f);
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= Loaded;
			Cleanup();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	[DefaultExecutionOrder(25000)]
	internal sealed class ResidentRoutine : MonoBehaviour
	{
		internal int Role;

		internal DialogueTreeController Dialogue;

		private Character body;

		private CharacterController motor;

		private Renderer[] renderers;

		private ResidentPlan plan;

		private Vector3[] corners;

		private int corner;

		private int stop;

		private float waitUntil;

		private float nextCheck;

		private float nextPath;

		private float stuckTime;

		private float nextWarning;

		private Vector3 lastPosition;

		private bool active;

		private bool near;

		private bool supported = true;

		private readonly NavMeshPath path = new NavMeshPath();

		private CourierWalking courier;

		internal void Setup(Character character, int role)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			body = character;
			Role = role;
			plan = TownPlan.Residents[role];
			motor = body.CharacterController;
			if ((Object)(object)motor == (Object)null)
			{
				throw new InvalidOperationException("CharacterController nativo ausente");
			}
			if ((Object)(object)body.CharacterControl != (Object)null)
			{
				((Behaviour)body.CharacterControl).enabled = false;
			}
			NavMeshAgent component = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			((Collider)motor).enabled = true;
			Vector3 center = motor.center;
			center.y = motor.height * 0.5f - 0.12f;
			motor.center = center;
			body.ResetCastType();
			body.ForceBackToLocomotion();
			renderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
			lastPosition = ((Component)this).transform.position;
			waitUntil = Time.time + TownPlan.WaitSeconds(Role, 0, Plugin.Instance.Night);
			if (Role == 3)
			{
				courier = new CourierWalking(body, motor);
			}
		}

		private void LateUpdate()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0562: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: 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_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: 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_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			Plugin instance = Plugin.Instance;
			if ((Object)(object)body == (Object)null || (Object)(object)instance == (Object)null || (Object)(object)motor == (Object)null)
			{
				return;
			}
			float num = instance.DistanceSquared(((Component)this).transform.position);
			Vector3 floor;
			if (Time.unscaledTime >= nextCheck)
			{
				nextCheck = Time.unscaledTime + 0.4f;
				near = num < 14.44f;
				supported = ((Role == 3) ? WorldGround.Try(((Component)this).transform.position, out floor, out var support) : Plugin.Surface(((Component)this).transform.position, out floor, out support));
				bool enabled = num < 52900f;
				Renderer[] array = renderers;
				foreach (Renderer val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.enabled = enabled;
					}
				}
				bool flag = (Object)(object)Dialogue != (Object)null && ((GraphOwner)Dialogue).isRunning;
				active = ((Role != 3) ? TownPlan.AwakeNear(num, instance.Gameplay, flag) : (instance.Gameplay && !flag && num <= 422500f));
			}
			if (!instance.Gameplay || !active || near || !supported)
			{
				body.SetAnimMove(0f, 0f);
				return;
			}
			if (courier != null)
			{
				courier.Tick();
				return;
			}
			if (Time.time < waitUntil)
			{
				body.SetAnimMove(0f, 0f);
				return;
			}
			if (corners == null)
			{
				if (Time.unscaledTime < nextPath)
				{
					body.SetAnimMove(0f, 0f);
					return;
				}
				nextPath = Time.unscaledTime + 3f;
				int num2 = TownPlan.NextStop(stop, plan.Stops.GetLength(0));
				NavMeshHit val2 = default(NavMeshHit);
				NavMeshHit val3 = default(NavMeshHit);
				if (!Plugin.Surface(Plugin.World(plan.Stops[num2, 0], plan.Stops[num2, 1]), out var floor2, out var support2) || !Plugin.ClearBody(floor2, support2, body) || !NavMesh.SamplePosition(((Component)this).transform.position, ref val2, 1.5f, -1) || !NavMesh.SamplePosition(floor2, ref val3, 1.5f, -1) || Math.Abs(((NavMeshHit)(ref val2)).position.y - ((Component)this).transform.position.y) > 0.65f || Math.Abs(((NavMeshHit)(ref val3)).position.y - floor2.y) > 0.65f || !NavMesh.CalculatePath(((NavMeshHit)(ref val2)).position, ((NavMeshHit)(ref val3)).position, -1, path) || (int)path.status != 0)
				{
					body.SetAnimMove(0f, 0f);
					if (Time.unscaledTime >= nextWarning)
					{
						nextWarning = Time.unscaledTime + 30f;
						instance.Log("ROTA AGUARDANDO " + plan.Name + ";diálogo permanece disponível;sem teleporte de caminhada.");
					}
					return;
				}
				Vector3[] array2 = path.corners;
				bool flag2 = true;
				Vector3[] array3 = array2;
				foreach (Vector3 val4 in array3)
				{
					if (Math.Abs(val4.y - floor2.y) > 0.65f || !TownPlan.PathPointAllowed(Role, val4.x - 1783f, val4.z - 1796.7f))
					{
						flag2 = false;
					}
				}
				if (!flag2)
				{
					body.SetAnimMove(0f, 0f);
					return;
				}
				corners = array2;
				corner = 0;
				stop = num2;
				stuckTime = 0f;
			}
			while (corner < corners.Length)
			{
				floor = Horizontal(corners[corner] - ((Component)this).transform.position);
				if (!(((Vector3)(ref floor)).sqrMagnitude < 0.16f))
				{
					break;
				}
				corner++;
			}
			if (corner >= corners.Length)
			{
				corners = null;
				waitUntil = Time.time + TownPlan.WaitSeconds(Role, stop, instance.Night);
				body.SetAnimMove(0f, 0f);
				if (Role == 0)
				{
					((Component)this).transform.rotation = Quaternion.Euler(0f, 180f, 0f);
				}
				return;
			}
			floor = Horizontal(corners[corner] - ((Component)this).transform.position);
			Vector3 normalized = ((Vector3)(ref floor)).normalized;
			float num3 = Mathf.Min(Time.deltaTime, 0.05f);
			((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(normalized), 140f * num3);
			motor.Move((normalized * 1.15f + Vector3.down) * num3);
			floor = Horizontal(((Component)this).transform.position - lastPosition);
			float magnitude = ((Vector3)(ref floor)).magnitude;
			lastPosition = ((Component)this).transform.position;
			body.SetAnimMove(0f, (num3 > 0f) ? Mathf.Min(1.4f, magnitude / num3) : 0f);
			stuckTime = ((magnitude < num3 * 0.1f) ? (stuckTime + num3) : 0f);
			if (stuckTime > 2f)
			{
				corners = null;
				waitUntil = Time.time + 5f;
				body.SetAnimMove(0f, 0f);
			}
		}

		private static Vector3 Horizontal(Vector3 v)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			v.y = 0f;
			return v;
		}

		internal string Reply(int topic)
		{
			if (topic == 3)
			{
				Plugin.Instance?.Landmarks?.Celebrate();
			}
			return TownPlan.Answer(Role, topic, (Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.Night);
		}

		private void OnDisable()
		{
			if ((Object)(object)body != (Object)null && (Object)(object)body.Animator != (Object)null)
			{
				body.SetAnimMove(0f, 0f);
			}
		}
	}
	internal static class TownDialogue
	{
		internal static bool Attach(Character body, ResidentRoutine host)
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			GameObject val = Resources.Load<GameObject>("editor/templates/TrainerTemplate");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val);
			((Object)val2).name = "CidadeViva_Dialogo_" + host.Role;
			val2.transform.SetParent(((Component)body).transform, false);
			try
			{
				DialogueTreeController componentInChildren = val2.GetComponentInChildren<DialogueTreeController>(true);
				DialogueActor componentInChildren2 = val2.GetComponentInChildren<DialogueActor>(true);
				Graph val3 = (((Object)(object)componentInChildren == (Object)null) ? null : ((GraphOwner)componentInChildren).graph);
				DialogueTree val4 = (DialogueTree)(object)((val3 is DialogueTree) ? val3 : null);
				if (!(val3 is DialogueTreeExt) || (Object)(object)componentInChildren2 == (Object)null)
				{
					throw new InvalidOperationException("TrainerTemplate incompleto");
				}
				if (!(At.GetField<DialogueTree>(val4, "_actorParameters") is List<ActorParameter> { Count: not 0 } list))
				{
					throw new InvalidOperationException("Actor do diálogo ausente");
				}
				string name = body.Name;
				componentInChildren2.SetName(name);
				list[0].actor = (IDialogueActor)(object)componentInChildren2;
				list[0].name = name;
				val3.allNodes.Clear();
				StatementNodeExt val5 = Line(val3, name, "");
				TownTalkNode townTalkNode = val3.AddNode<TownTalkNode>();
				townTalkNode.Role = host.Role;
				townTalkNode.Topic = -1;
				townTalkNode.Output = val5;
				val3.primeNode = (Node)(object)townTalkNode;
				val3.ConnectNodes((Node)(object)townTalkNode, (Node)(object)val5, -1, -1);
				MultipleChoiceNodeExt val6 = val3.AddNode<MultipleChoiceNodeExt>();
				val3.ConnectNodes((Node)(object)val5, (Node)(object)val6, -1, -1);
				string[] array = ((host.Role != 2) ? new string[4] { "Onde ficam os pontos da cidade?", "Como passa o seu dia?", "O que se comenta por aqui?", "Até mais." } : new string[5] { "Como está nossa cidade?", "Como passa o seu dia?", "Conte a história das muralhas.", "Acenda a luz por quem voltou.", "Até mais." });
				for (int i = 0; i < array.Length; i++)
				{
					val6.availableChoices.Add(new Choice(new Statement(array[i])));
					StatementNodeExt val7 = Line(val3, name, (i == array.Length - 1) ? "Boa viagem, líder. Esta cidade espera sua volta." : "");
					if (i == array.Length - 1)
					{
						val3.ConnectNodes((Node)(object)val6, (Node)(object)val7, i, -1);
						continue;
					}
					TownTalkNode townTalkNode2 = val3.AddNode<TownTalkNode>();
					townTalkNode2.Role = host.Role;
					townTalkNode2.Topic = i;
					townTalkNode2.Output = val7;
					val3.ConnectNodes((Node)(object)val6, (Node)(object)townTalkNode2, i, -1);
					val3.ConnectNodes((Node)(object)townTalkNode2, (Node)(object)val7, -1, -1);
					val3.ConnectNodes((Node)(object)val7, (Node)(object)val6, -1, -1);
				}
				host.Dialogue = componentInChildren;
				val2.SetActive(true);
				return true;
			}
			catch
			{
				Object.Destroy((Object)(object)val2);
				throw;
			}
		}

		private static StatementNodeExt Line(Graph graph, string speaker, string text)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			StatementNodeExt obj = graph.AddNode<StatementNodeExt>();
			obj.SetActorName(speaker);
			obj.statement = new Statement(text);
			obj.ContinueOnStatementFinished = true;
			return obj;
		}
	}
	public sealed class TownTalkNode : DTNode
	{
		public int Role;

		public int Topic;

		public StatementNodeExt Output;

		public override bool requireActorSelection => false;

		protected override Status OnExecute(Component agent, IBlackboard bb)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			ResidentRoutine residentRoutine = Plugin.Instance?.Resident(Role);
			if (!((Object)(object)residentRoutine == (Object)null) && Output != null)
			{
				Output.statement = new Statement((Topic < 0) ? TownPlan.Greeting(Role, (Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.Night) : residentRoutine.Reply(Topic));
				((DTNode)this).DLGTree.Continue(0);
				return (Status)1;
			}
			return (Status)4;
		}
	}
	internal sealed class CanopyData
	{
		internal readonly List<Vector3> Points = new List<Vector3>();

		internal readonly List<Vector2> UV = new List<Vector2>();

		internal readonly List<int> Triangles = new List<int>();
	}
	internal static class TownGeometry
	{
		internal static CanopyData Pennant(float width, float height)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			CanopyData canopyData = new CanopyData();
			int num = 99;
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j <= 8; j++)
				{
					for (int k = 0; k <= 10; k++)
					{
						float num2 = (float)k / 10f;
						float num3 = (float)j / 8f;
						float num4 = Math.Abs(num2 - 0.5f) * 0.16f;
						canopyData.Points.Add(new Vector3((num2 - 0.5f) * width, (num3 - 0.5f) * height + (1f - num3) * num4, 0.055f * (float)Math.Sin(num2 * 9f + num3 * 2f) * num3 + (float)i * 0.022f));
						canopyData.UV.Add(new Vector2(num2, num3));
					}
				}
			}
			for (int l = 0; l < 2; l++)
			{
				for (int m = 0; m < 8; m++)
				{
					for (int n = 0; n < 10; n++)
					{
						int num5 = l * num + m * 11 + n;
						int num6 = num5 + 1;
						int num7 = num5 + 10 + 1;
						int num8 = num7 + 1;
						canopyData.Triangles.AddRange((l == 0) ? new int[6] { num5, num7, num6, num6, num7, num8 } : new int[6] { num5, num6, num7, num6, num8, num7 });
					}
				}
			}
			List<int> list = new List<int>();
			for (int num9 = 0; num9 <= 10; num9++)
			{
				list.Add(num9);
			}
			for (int num10 = 1; num10 <= 8; num10++)
			{
				list.Add(num10 * 11 + 10);
			}
			for (int num11 = 9; num11 >= 0; num11--)
			{
				list.Add(88 + num11);
			}
			for (int num12 = 7; num12 > 0; num12--)
			{
				list.Add(num12 * 11);
			}
			for (int num13 = 0; num13 < list.Count; num13++)
			{
				int num14 = list[num13];
				int num15 = list[(num13 + 1) % list.Count];
				canopyData.Triangles.AddRange(new int[6]
				{
					num14,
					num15,
					num14 + num,
					num15,
					num15 + num,
					num14 + num
				});
			}
			return canopyData;
		}

		internal static CanopyData Canopy()
		{
			//IL_00c6: 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)
			CanopyData canopyData = new CanopyData();
			List<Vector3> points = canopyData.Points;
			List<Vector2> uV = canopyData.UV;
			List<int> triangles = canopyData.Triangles;
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j <= 6; j++)
				{
					for (int k = 0; k <= 12; k++)
					{
						float num = -3f + 6f * (float)k / 12f;
						float num2 = -1.9f + 3.8f * (float)j / 6f;
						float num3 = 3.45f - Math.Abs(num) * 0.11f - 0.14f * (float)Math.Sin((double)j * Math.PI / 6.0) + 0.025f * (float)Math.Sin((float)k * 1.2f + (float)j) - (float)i * 0.045f;
						points.Add(new Vector3(num, num3, num2));
						uV.Add(new Vector2((float)k / 4f, (float)j / 3f));
					}
				}
			}
			int num4 = 91;
			for (int l = 0; l < 2; l++)
			{
				for (int m = 0; m < 6; m++)
				{
					for (int n = 0; n < 12; n++)
					{
						int num5 = l * num4 + m * 13 + n;
						int num6 = num5 + 1;
						int num7 = num5 + 12 + 1;
						int num8 = num7 + 1;
						if (l == 0)
						{
							triangles.AddRange(new int[6] { num5, num7, num6, num6, num7, num8 });
						}
						else
						{
							triangles.AddRange(new int[6] { num5, num6, num7, num6, num8, num7 });
						}
					}
				}
			}
			List<int> list = new List<int>();
			for (int num9 = 0; num9 <= 12; num9++)
			{
				list.Add(num9);
			}
			for (int num10 = 1; num10 <= 6; num10++)
			{
				list.Add(num10 * 13 + 12);
			}
			for (int num11 = 11; num11 >= 0; num11--)
			{
				list.Add(78 + num11);
			}
			for (int num12 = 5; num12 > 0; num12--)
			{
				list.Add(num12 * 13);
			}
			for (int num13 = 0; num13 < list.Count; num13++)
			{
				int num14 = list[num13];
				int num15 = list[(num13 + 1) % list.Count];
				triangles.AddRange(new int[6]
				{
					num14,
					num15,
					num14 + num4,
					num15,
					num15 + num4,
					num14 + num4
				});
			}
			return canopyData;
		}
	}
	internal sealed class TownLandmarks : MonoBehaviour
	{
		private readonly List<Object> owned = new List<Object>();

		private Material wood;

		private Material stone;

		private Material cloth;

		private Material brass;

		private Renderer[] renderers;

		private ParticleSystem ceremony;

		private float nextCeremony;

		internal static TownLandmarks Build()
		{
			//IL_0020: 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_005e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			GameObject val = GameObject.Find("Codex_Complexo_Negro_Teste");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if (!Plugin.Surface(Plugin.World(-43f, -7f), out var _, out var support) || !Plugin.Surface(Plugin.World(-21f, 30f), out var _, out var _))
			{
				return null;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[2]
			{
				Plugin.World(-43f, -7f),
				Plugin.World(-21f, 30f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				Collider[] array2 = Physics.OverlapBox(array[i] + Vector3.up * 1.7f, new Vector3(3.5f, 1.5f, 2f), Quaternion.identity, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				foreach (Collider val2 in array2)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)support)
					{
						Plugin.Instance.Log("MARCO aguardando espaço ocupado: " + ((Object)val2).name);
						return null;
					}
				}
			}
			GameObject val3 = new GameObject("Codex_Cidade_Viva_Marcos");
			SceneManagerMove(val3, support);
			TownLandmarks townLandmarks = val3.AddComponent<TownLandmarks>();
			try
			{
				townLandmarks.Create(val, ((Component)support).gameObject.layer);
				return townLandmarks;
			}
			catch
			{
				Object.Destroy((Object)(object)val3);
				throw;
			}
		}

		private static void SceneManagerMove(GameObject root, Collider support)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			SceneManager.MoveGameObjectToScene(root, ((Component)support).gameObject.scene);
		}

		private T Own<T>(T value) where T : Object
		{
			owned.Add((Object)(object)value);
			return value;
		}

		private Material Material(Color color, Material source = null)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Material val = Own<Material>(((Object)(object)source != (Object)null) ? new Material(source) : new Material(Shader.Find("Standard") ?? Shader.Find("Diffuse")));
			val.color = color;
			val.enableInstancing = true;
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.22f);
			}
			return val;
		}

		private void Create(GameObject town, int layer)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Laje_Cidade_Continua");
			Renderer val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Renderer>());
			Material source = null;
			MonoBehaviour[] components = town.GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val3 in components)
			{
				if (((object)val3).GetType().Name == "RoomAssetScope")
				{
					object? obj = ((object)val3).GetType().GetField("SupplyWood", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val3);
					source = (Material)((obj is Material) ? obj : null);
				}
			}
			wood = Material(new Color(0.72f, 0.64f, 0.54f), source);
			stone = Material(new Color(0.82f, 0.87f, 0.89f), (val2 != null) ? val2.sharedMaterial : null);
			brass = Material(new Color(0.67f, 0.49f, 0.2f));
			cloth = Material(new Color(0.13f, 0.36f, 0.42f));
			cloth.mainTexture = (Texture)(object)Fabric();
			Market(layer);
			Plaza(layer);
			Banner("Entrada_Gelo", new Vector3(49f, 0f, 34f), layer);
			Pennant("Sede_Estandarte_E", new Vector3(2f, 2.8f, -24.65f), 1f, 2.5f);
			Pennant("Sede_Estandarte_D", new Vector3(14f, 2.8f, -24.65f), 1f, 2.5f);
			CreateCeremony();
			renderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
			Show(show: true);
		}

		private Texture2D Fabric()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = Own<Texture2D>(new Texture2D(128, 128, (TextureFormat)3, true));
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = 0.79f + ((j % 3 == 0 || i % 3 == 0) ? 0.12f : 0f) + Mathf.PerlinNoise((float)j * 0.19f, (float)i * 0.17f) * 0.07f;
					array[i * 128 + j] = new Color(num, num, num);
				}
			}
			val.SetPixels(array);
			val.Apply(true, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			return val;
		}

		private GameObject Piece(string name, PrimitiveType primitive, Vector3 local, Vector3 scale, Material material, int layer, bool solid)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(primitive);
			((Object)obj).name = "CidadeViva_" + name;
			obj.transform.SetParent(((Component)this).transform, false);
			obj.transform.position = Plugin.World(local.x, local.z) + Vector3.up * local.y;
			obj.transform.localScale = scale;
			Renderer component = obj.GetComponent<Renderer>();
			component.sharedMaterial = material;
			component.shadowCastingMode = (ShadowCastingMode)0;
			obj.layer = layer;
			Collider component2 = obj.GetComponent<Collider>();
			if (!solid && (Object)(object)component2 != (Object)null)
			{
				component2.enabled = false;
				Object.Destroy((Object)(object)component2);
			}
			return obj;
		}

		private void Obstacle(GameObject go, Vector3 size)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			NavMeshObstacle obj = go.AddComponent<NavMeshObstacle>();
			obj.shape = (NavMeshObstacleShape)1;
			obj.size = size;
			obj.carving = true;
			obj.carveOnlyStationary = true;
		}

		private void Market(int layer)
		{
			//IL_0091: 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_00ba: 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_004e: 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_0067: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0141: 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_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: 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)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(-43f, 0f, -7f);
			for (int i = -1; i <= 1; i += 2)
			{
				for (int j = -1; j <= 1; j += 2)
				{
					Piece("Mercado_Poste_" + i + j, (PrimitiveType)2, val + new Vector3((float)i * 2.7f, 1.7f, (float)j * 1.6f), new Vector3(0.17f, 1.7f, 0.17f), wood, layer, solid: true);
				}
			}
			GameObject go = Piece("Mercado_Balcão", (PrimitiveType)3, val + new Vector3(0f, 0.92f, -0.2f), new Vector3(5.2f, 0.18f, 1.3f), wood, layer, solid: true);
			for (int k = -1; k <= 1; k += 2)
			{
				Piece("Mercado_Pés_" + k, (PrimitiveType)3, val + new Vector3((float)k * 2.1f, 0.43f, -0.2f), new Vector3(0.28f, 0.86f, 1f), wood, layer, solid: true);
			}
			Obstacle(go, new Vector3(1f, 5f, 1f));
			Canopy(val);
			for (int l = 0; l < 8; l++)
			{
				Piece("Mercado_Cesto_" + l, (PrimitiveType)2, val + new Vector3(-2.1f + (float)l * 0.6f, 1.05f, -0.2f), new Vector3(0.46f, 0.1f, 0.48f), wood, layer, solid: false);
				Piece("Mercado_Provisão_" + l, (PrimitiveType)0, val + new Vector3(-2.1f + (float)l * 0.6f, 1.2f, -0.2f), new Vector3(0.32f, 0.24f, 0.35f), (l % 2 == 0) ? brass : stone, layer, solid: false);
			}
		}

		private void Canopy(Vector3 center)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0054: 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)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			CanopyData canopyData = TownGeometry.Canopy();
			Mesh val = Own<Mesh>(new Mesh
			{
				name = "Toldo_Mercado_Fechado"
			});
			val.SetVertices(canopyData.Points);
			val.SetUVs(0, canopyData.UV);
			val.SetTriangles(canopyData.Triangles, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject("CidadeViva_Toldo_Mercado");
			val2.transform.SetParent(((Component)this).transform, false);
			val2.transform.position = Plugin.World(center.x, center.z);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = cloth;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		}

		private void Plaza(int layer)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0041: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			//IL_00a5: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(-21f, 0f, 30f);
			GameObject go = Piece("Praça_Memorial_Base", (PrimitiveType)2, val + Vector3.up * 0.32f, new Vector3(2.6f, 0.32f, 2.6f), stone, layer, solid: true);
			Obstacle(go, Vector3.one);
			Piece("Praça_Memorial_Coluna", (PrimitiveType)2, val + Vector3.up * 1.15f, new Vector3(0.55f, 0.55f, 0.55f), stone, layer, solid: true);
			Piece("Praça_Brasa_Cálice", (PrimitiveType)0, val + Vector3.up * 1.8f, new Vector3(0.9f, 0.35f, 0.9f), brass, layer, solid: false);
			GameObject go2 = Piece("Praça_Banco", (PrimitiveType)3, new Vector3(-21f, 0.7f, 24f), new Vector3(3.2f, 0.16f, 0.8f), wood, layer, solid: true);
			Obstacle(go2, new Vector3(1f, 5f, 1f));
			for (int i = -1; i <= 1; i += 2)
			{
				Piece("Praça_Banco_Pe" + i, (PrimitiveType)2, new Vector3(-21f + (float)i * 1.15f, 0.3f, 24f), new Vector3(0.35f, 0.3f, 0.55f), stone, layer, solid: true);
			}
		}

		private void Banner(string name, Vector3 origin, int layer)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Piece(name + "_Poste", (PrimitiveType)2, origin + Vector3.up * 2f, new Vector3(0.18f, 2f, 0.18f), wood, layer, solid: true);
			Pennant(name + "_Pano", origin + new Vector3(0.65f, 2.9f, 0f), 1.1f, 1.6f);
		}

		private void Pennant(string name, Vector3 at, float width, float height)
		{
			//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_0025: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			CanopyData canopyData = TownGeometry.Pennant(width, height);
			Mesh val = Own<Mesh>(new Mesh
			{
				name = "Pano_" + name
			});
			val.SetVertices(canopyData.Points);
			val.SetUVs(0, canopyData.UV);
			val.SetTriangles(canopyData.Triangles, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject("CidadeViva_" + name);
			val2.transform.SetParent(((Component)this).transform, false);
			val2.transform.position = Plugin.World(at.x, at.z) + Vector3.up * at.y;
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = cloth;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			Piece(name + "_Emblema", (PrimitiveType)0, at + new Vector3(0f, 0f, -0.05f), new Vector3(width * 0.37f, width * 0.45f, 0.04f), brass, 0, solid: false);
		}

		private void CreateCeremony()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00de: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Expected O, but got Unknown
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Expected O, but got Unknown
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CidadeViva_Luz_do_Retorno");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.position = Plugin.World(-21f, 30f) + Vector3.up * 1.98f;
			val.transform.rotation = Quaternion.Euler(-90f, 0f, 0f);
			ceremony = val.AddComponent<ParticleSystem>();
			ceremony.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = ceremony.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).duration = 3f;
			((MainModule)(ref main)).maxParticles = 48;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.2f, 2.5f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.035f, 0.08f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.4f, 0.9f);
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.03f);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.22f, 0.7f, 1f, 0.8f), new Color(1f, 0.73f, 0.27f, 0.85f));
			EmissionModule emission = ceremony.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
			((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
			{
				new Burst(0f, (short)36)
			});
			ShapeModule shape = ceremony.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
			((ShapeModule)(ref shape)).radius = 0.35f;
			((ShapeModule)(ref shape)).angle = 28f;
			ColorOverLifetimeModule colorOverLifetime = ceremony.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val2 = new Gradient();
			val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.15f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
			Texture2D val3 = Own<Texture2D>(new Texture2D(64, 64, (TextureFormat)4, false));
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j - 31.5f) / 31.5f;
					float num2 = ((float)i - 31.5f) / 31.5f;
					array[i * 64 + j] = new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Max(0f, 1f - num * num - num2 * num2), 3f));
				}
			}
			val3.SetPixels(array);
			val3.Apply(false, true);
			Material val4 = Own<Material>(new Material(Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Standard Unlit")));
			val4.mainTexture = (Texture)(object)val3;
			ParticleSystemRenderer component = ((Component)ceremony).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = val4;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		}

		internal void Celebrate()
		{
			if (!((Object)(object)ceremony == (Object)null) && !(Time.unscaledTime < nextCeremony))
			{
				nextCeremony = Time.unscaledTime + 20f;
				ceremony.Play(true);
				Plugin.Instance?.Log("LUZ DO RETORNO:pedido de Dalia;36partículas/3s,sem dano ou recompensa.");
			}
		}

		internal void Show(bool show)
		{
			if (renderers == null)
			{
				return;
			}
			Renderer[] array = renderers;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = show;
				}
			}
			if (!show && (Object)(object)ceremony != (Object)null)
			{
				ceremony.Stop(true, (ParticleSystemStopBehavior)0);
			}
		}

		private void OnDestroy()
		{
			foreach (Object item in owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			owned.Clear();
		}
	}
	internal sealed class ResidentPlan
	{
		internal readonly string Uid;

		internal readonly string Name;

		internal readonly float[,] Stops;

		internal readonly int Chest;

		internal readonly int Boots;

		internal readonly bool Female;

		internal ResidentPlan(string key, string name, float[,] stops, int chest, int boots, bool female)
		{
			Uid = "codex.character.cidade.viva." + key;
			Name = name;
			Stops = stops;
			Chest = chest;
			Boots = boots;
			Female = female;
		}
	}
	internal static class TownPlan
	{
		internal const float RoomX = 1783f;

		internal const float RoomZ = 1796.7f;

		internal const float GroundY = 255f;

		internal const float ViewRange = 140f;

		internal const float WalkSpeed = 1.15f;

		internal const float TalkRange = 3.8f;

		internal static readonly ResidentPlan[] Residents = new ResidentPlan[4]
		{
			new ResidentPlan("nessa", "Nessa, Intendente do Mercado", new float[3, 2]
			{
				{ -43f, -5.1f },
				{ -44f, -5.1f },
				{ -42f, -5.1f }
			}, 3100080, 3100082, female: true),
			new ResidentPlan("ruan", "Ruan, Vigia da Passagem", new float[3, 2]
			{
				{ 51f, 40f },
				{ 54f, 43f },
				{ 54f, 48f }
			}, 3100150, 3100152, female: false),
			new ResidentPlan("dalia", "Dalia, Guardiã das Memórias", new float[3, 2]
			{
				{ -18f, 32f },
				{ -15f, 38f },
				{ -13f, 44f }
			}, 3100080, 3100082, female: true),
			new ResidentPlan("caio", "Caio, Mensageiro de Vale Manso", new float[14, 2]
			{
				{ 45f, 43f },
				{ 66f, 43f },
				{ 68f, 66f },
				{ -75f, 66f },
				{ -165f, 66f },
				{ -198f, 43f },
				{ -218f, 43f },
				{ -248f, 43f },
				{ -280f, 45f },
				{ -340f, 45f },
				{ -390f, 45f },
				{ -405f, 49.5f },
				{ -432f, 49.5f },
				{ -440f, 45f }
			}, 3100080, 3100082, female: false)
		};

		internal static bool AwakeNear(float distanceSquared, bool gameplay, bool talking)
		{
			if (gameplay && !talking)
			{
				return distanceSquared <= 19600f;
			}
			return false;
		}

		internal static float WaitSeconds(int resident, int stop, bool night)
		{
			return (night ? 24 : 12) + resident * 3 + stop * 4;
		}

		internal static int NextStop(int stop, int count)
		{
			if (count > 0)
			{
				return (stop + 1) % count;
			}
			return 0;
		}

		internal static bool PathPointAllowed(int role, float x, float z)
		{
			switch (role)
			{
			case 0:
				if (x >= -44.4f && x <= -41.6f && z >= -5.6f)
				{
					return z <= -4.6f;
				}
				return false;
			case 3:
			{
				float[,] stops = Residents[3].Stops;
				for (int i = 1; i < stops.GetLength(0); i++)
				{
					if (RouteDistance(x, z, stops[i - 1, 0], stops[i - 1, 1], stops[i, 0], stops[i, 1]) <= 3.0)
					{
						return true;
					}
				}
				return false;
			}
			case 2:
				if ((x + 21f) * (x + 21f) + (z - 30f) * (z - 30f) <= 5.29f)
				{
					return false;
				}
				break;
			}
			float[,] stops2 = Residents[role].Stops;
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			for (int j = 0; j < stops2.GetLength(0); j++)
			{
				num = Math.Min(num, stops2[j, 0]);
				num2 = Math.Max(num2, stops2[j, 0]);
				num3 = Math.Min(num3, stops2[j, 1]);
				num4 = Math.Max(num4, stops2[j, 1]);
			}
			if (x >= num - 2f && x <= num2 + 2f && z >= num3 - 2f)
			{
				return z <= num4 + 2f;
			}
			return false;
		}

		internal static double RouteDistance(float x, float z, float ax, float az, float bx, float bz)
		{
			double num = bx - ax;
			double num2 = bz - az;
			double num3 = Math.Max(0.0, Math.Min(1.0, ((double)(x - ax) * num + (double)(z - az) * num2) / (num * num + num2 * num2)));
			return Math.Sqrt(Math.Pow((double)(x - ax) - num3 * num, 2.0) + Math.Pow((double)(z - az) - num3 * num2, 2.0));
		}

		internal static int CourierNext(int stop, ref int direction)
		{
			int length = Residents[3].Stops.GetLength(0);
			if (stop == length - 1)
			{
				direction = -1;
			}
			if (stop == 0)
			{
				direction = 1;
			}
			return stop + direction;
		}

		internal static string Greeting(int role, bool night)
		{
			switch (role)
			{
			case 3:
				if (!night)
				{
					return "Bom dia, líder. Levo notícias da cidade até Vale Manso e volto pelo mesmo caminho. Um passo de cada vez, sem atalhos.";
				}
				return "Líder, ainda faço a última ronda entre as muralhas e Vale Manso. As provisões não chegam sozinhas.";
			case 0:
				if (!night)
				{
					return "Bem-vindo, líder. O mercado já recebeu as provisões de Vale Manso. Ninguém atravessa o gelo de estômago vazio.";
				}
				return "Boa noite, líder. Estou conferindo o estoque antes de fechar a banca. A cidade dorme, mas o abastecimento não.";
			case 1:
				if (!night)
				{
					return "Passagem livre, líder. O caminho de gelo fica a leste. Quem cruza esta cerca leva o nome da cidade consigo.";
				}
				return "Líder, a passagem está sob vigia. Lá fora o frio esconde os passos; aqui dentro contamos todos os que voltam.";
			default:
				if (!night)
				{
					return "Bom ver você na praça, líder. Dorian cuida dos relatórios; eu cuido de lembrar por que construímos estas muralhas.";
				}
				return "Líder... à noite a cidade parece escutar. A luz distante da arena não é uma estrela: é a obra que nós erguemos.";
			}
		}

		internal static string Answer(int role, int topic, bool night)
		{
			if (role == 3)
			{
				return topic switch
				{
					1 => "Visito a entrada da fazenda, descanso um pouco e retorno às muralhas. Se você precisar falar, faço uma pausa.", 
					0 => "Saio pela passagem do gelo, contorno a cerca pelo norte e cruzo a abertura oeste do cânion. Vale Manso fica logo adiante.", 
					_ => "Uma estrada conhecida ainda pode trazer notícias novas. Nossa cidade precisa desses laços tanto quanto das muralhas.", 
				};
			}
			if (topic == 3)
			{
				return "As muralhas guardam nossos corpos. Uns aos outros, guardamos o que vale a pena proteger.";
			}
			switch (role)
			{
			case 0:
				switch (topic)
				{
				default:
					return "O sol artificial nos deu coragem, não comida. Uma cidade precisa de engenheiros... e de alguém que se lembre do jantar.";
				case 1:
					if (!night)
					{
						return "Confiro as provisões, ouço os viajantes e volto à banca. Sempre há alguém com fome, ou uma boa história para contar.";
					}
					return "Estou contando sacos e fechando as contas. Amanhã volto a conferir a chegada de provisões.";
				case 0:
					return "A praça fica ao norte da sede. A banca é nosso ponto de encontro e abastecimento; as casas do lado de fora ainda dependem das caravanas de Vale Manso.";
				}
			case 1:
				switch (topic)
				{
				default:
					return "Kael e Nara trabalham perto da Fornalha. O sol artificial ilumina a arena sem descanso; a ameaça é o Colosso, não nossa luz.";
				case 1:
					if (!night)
					{
						return "Inspeciono o caminho de gelo. Se o vento trouxer um viajante de volta, ele encontrará esta passagem aberta.";
					}
					return "Vigio a passagem e os cantos da cerca. Com pouca luz, prefiro passos curtos e olhos atentos.";
				case 0:
					return "A sede é a casa do portal azul. A praça e o mercado ficam à esquerda dela. Dorian espera ao norte para falar com você.";
				}
			default:
				return topic switch
				{
					1 => "Caminho pela praça, observo as muralhas e paro para ouvir quem chega. Até uma cidade de pedra precisa de memória.", 
					0 => "A sede acolhe quem chega pelo portal. O mercado sustenta a cidade, a praça reúne suas histórias e a passagem nos liga ao gelo. Você lidera todos esses caminhos.", 
					_ => "Antes das muralhas, carregávamos brasas nas mãos para achar o caminho. Hoje temos portais e até um sol feito por gente... mas ainda acendemos uma pequena luz por quem volta.", 
				};
			}
		}
	}
	public sealed class GroundedFind : SL_ItemSpawn
	{
		internal FindLot Lot;

		internal bool Attempted;

		internal Item Generate()
		{
			return ((SL_ItemSpawn)this).GenerateItem();
		}

		protected override void ApplyToItem(Item item)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && string.IsNullOrEmpty(item.MostRecentOwnerUID) && !item.IsInContainer)
			{
				Vector3 val = Plugin.World(Lot.X, Lot.Z);
				val.y = 280f;
				base.SpawnPosition = (WorldGround.Try(val, out var floor, out var _) ? (floor + Vector3.up * 0.16f) : val);
				((SL_ItemSpawn)this).ApplyToItem(item);
				(((Component)item).GetComponent<PlaceFind>() ?? ((Component)item).gameObject.AddComponent<PlaceFind>()).Setup(item, Lot);
			}
		}
	}
	internal sealed class PlaceFind : MonoBehaviour
	{
		private Item item;

		private FindLot lot;

		private float next;

		internal void Setup(Item item, FindLot lot)
		{
			this.item = item;
			this.lot = lot;
			next = 0f;
		}

		private void Update()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)item == (Object)null)
			{
				Object.Destroy((Object)(object)this);
			}
			else if (!string.IsNullOrEmpty(item.MostRecentOwnerUID) || item.IsInContainer)
			{
				Object.Destroy((Object)(object)this);
			}
			else
			{
				if ((Object)(object)Plugin.Instance == (Object)null || !Plugin.Instance.Gameplay || Time.unscaledTime < next)
				{
					return;
				}
				next = Time.unscaledTime + 1f;
				if (!WorldGround.Try(Plugin.World(lot.X, lot.Z), out var floor, out var support))
				{
					return;
				}
				Collider[] array = Physics.OverlapCapsule(floor + Vector3.up * 0.75f, floor + Vector3.up * 1.7f, 0.42f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				foreach (Collider val in array)
				{
					if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)support && (Object)(object)((Component)val).GetComponentInParent<Item>() != (Object)(object)item)
					{
						return;
					}
				}
				item.ChangeParent((Transform)null, floor + Vector3.up * 0.16f, Quaternion.Euler(0f, 35f, 90f));
				item.ResetTargetMove();
				item.SetForceSyncPos();
				Plugin instance = Plugin.Instance;
				string[] obj = new string[9] { "ACHADO APOIADO ", lot.Key, ";item=", null, null, null, null, null, null };
				int i = lot.ItemId;
				obj[3] = i.ToString();
				obj[4] = ";uid=";
				obj[5] = item.UID;
				obj[6] = ";piso=";
				obj[7] = ((Object)support).name;
				obj[8] = ";coletável/salvável nativo.";
				instance.Log(string.Concat(obj));
				Object.Destroy((Object)(object)this);
			}
		}
	}
	internal sealed class WorldFinds
	{
		private readonly GroundedFind[] sources = Array.ConvertAll(FindsPlan.Lots, (FindLot lot) => new GroundedFind
		{
			Lot = lot,
			IdentifierName = lot.Key,
			ItemID = lot.ItemId,
			Quantity = 1,
			SceneToSpawnIn = "",
			SpawnPosition = new Vector3(1783f + lot.X, 280f, 1796.7f + lot.Z),
			SpawnRotation = new Vector3(0f, 35f, 90f),
			ForceNonPickable = false
		});

		private List<Character> players = new List<Character>();

		private int slot;

		private float next;

		internal void Prepare()
		{
			GroundedFind[] array = sources;
			for (int i = 0; i < array.Length; i++)
			{
				((ContentTemplate)array[i]).ApplyTemplate();
			}
		}

		internal void Reset()
		{
			GroundedFind[] array = sources;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Attempted = false;
			}
			next = 0f;
		}

		internal void Tick()
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < next || PhotonNetwork.isNonMasterClientInRoom || (Object)(object)ItemManager.Instance == (Object)null || ResourcesPrefabManager.Instance == null)
			{
				return;
			}
			next = Time.unscaledTime + 0.4f;
			GroundedFind groundedFind = sources[slot];
			slot = (slot + 1) % sources.Length;
			if (groundedFind.Attempted)
			{
				return;
			}
			Vector3 val = Plugin.World(groundedFind.Lot.X, groundedFind.Lot.Z);
			players.Clear();
			CharacterManager.Instance.FindCharactersInRange(val, 120f, ref players);
			bool flag = false;
			foreach (Character player in players)
			{
				if ((Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && ((Component)player).transform.position.y > 220f)
				{
					flag = true;
				}
			}
			if (!flag || (Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(((SL_ItemSpawn)groundedFind).ItemID) == (Object)null || !WorldGround.Try(val, out var floor, out var support) || !Plugin.ClearBody(floor, support, null))
			{
				return;
			}
			((SL_ItemSpawn)groundedFind).SpawnPosition = floor + Vector3.up * 0.16f;
			groundedFind.Attempted = true;
			try
			{
				Item val2 = groundedFind.Generate();
				Plugin.Instance.Log(((Object)(object)val2 == (Object)null) ? ("ACHADO JA REGISTRADO " + groundedFind.Lot.Key + ";sem criar segunda copia.") : ("ACHADO CRIADO " + groundedFind.Lot.Name + ";item=" + ((SL_ItemSpawn)groundedFind).ItemID + ";UID=" + val2.UID));
			}
			catch (Exception ex)
			{
				Plugin.Instance.Log("ACHADO FALHOU " + groundedFind.Lot.Key + ";sem repetir geracao:" + ex);
			}
		}
	}
	internal static class WorldGround
	{
		private static GameObject root;

		private static Collider[] surfaces;

		private static float nextRefresh;

		internal static bool Allowed(string name)
		{
			switch (name)
			{
			default:
				return name.StartsWith("Campo_Oeste_Setor_", StringComparison.Ordinal);
			case "Piso_Principal_Colisor":
			case "Campo_Branco_Cidade":
			case "Neve_Pe_Canion":
			case "Passagem_Oeste_Canion":
			case "Neve_Exterior_Canion":
			case "CampoMecanico_Arena_Piso":
			case "Pantano_Passarela":
				return true;
			}
		}

		internal static bool Try(Vector3 guess, out Vector3 floor, out Collider support)
		{
			//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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			floor = guess;
			support = null;
			GameObject val = GameObject.Find("Codex_Complexo_Negro_Teste");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if ((Object)(object)root != (Object)(object)val || surfaces == null || Time.unscaledTime >= nextRefresh)
			{
				root = val;
				nextRefresh = Time.unscaledTime + 5f;
				surfaces = Array.FindAll(root.GetComponentsInChildren<Collider>(true), (Collider c) => (Object)(object)c != (Object)null && !c.isTrigger && Allowed(((Object)c).name));
			}
			float num = 220f;
			Ray val2 = default(Ray);
			((Ray)(ref val2))..ctor(new Vector3(guess.x, 305f, guess.z), Vector3.down);
			Collider[] array = surfaces;
			RaycastHit val4 = default(RaycastHit);
			foreach (Collider val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && val3.enabled && ((Component)val3).gameObject.activeInHierarchy)
				{
					Bounds bounds = val3.bounds;
					if (!(guess.x < ((Bounds)(ref bounds)).min.x) && !(guess.x > ((Bounds)(ref bounds)).max.x) && !(guess.z < ((Bounds)(ref bounds)).min.z) && !(guess.z > ((Bounds)(ref bounds)).max.z) && val3.Raycast(val2, ref val4, 85f) && ((RaycastHit)(ref val4)).normal.y > 0.7f && ((RaycastHit)(ref val4)).point.y > num && ((RaycastHit)(ref val4)).point.y < 300f)
					{
						num = ((RaycastHit)(ref val4)).point.y;
						floor = ((RaycastHit)(ref val4)).point;
						support = val3;
					}
				}
			}
			return (Object)(object)support != (Object)null;
		}
	}
}

BepInEx/plugins/Codex_Combo_Rubro/CodexComboRubro.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexCombat;
using CodexCorteCarmesim;
using CodexHumanoidExtras;
using CodexSkillIcons;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexSkillIcons
{
	internal static class SkillIcon
	{
		private static readonly HashSet<Sprite> owned = new HashSet<Sprite>();

		internal static Sprite Load(string folder, Func<Sprite> fallback, Action<string> warning)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = null;
			Sprite val2 = null;
			try
			{
				val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					name = "Codex_SkillIcon_Painted",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)2
				};
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, "UI", "skill-icon.png")), false) || ((Texture)val).width != 512 || ((Texture)val).height != 512)
				{
					throw new InvalidDataException("Expected512x512 skill-icon.png");
				}
				val.Apply(true, true);
				val2 = Sprite.Create(val, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidDataException("Icon Sprite unavailable");
				}
				owned.Add(val2);
				return val2;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				warning?.Invoke("ICON_FALLBACK:" + ex.Message);
				return fallback();
			}
		}

		internal static void Release(Sprite sprite)
		{
			if (!((Object)(object)sprite == (Object)null) && owned.Remove(sprite))
			{
				Object.Destroy((Object)(object)sprite.texture);
				Object.Destroy((Object)(object)sprite);
			}
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexComboRubro
{
	internal static class ComboAttack
	{
		internal const float ContactDamage = 80f;

		internal const float ContactImpact = 12f;

		internal const float WaveDamage = 80f;

		internal const float WaveImpact = 8f;

		internal const float Reach = 3f;

		internal const float Range = 10f;

		internal const float Speed = 20f;

		internal const float Radius = 0.48f;

		internal static Character Victim(Character owner, Collider collider)
		{
			Hitbox componentInParent = ((Component)collider).GetComponentInParent<Hitbox>();
			Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val != (Object)(object)owner) || !val.Alive || val.IsLocalPlayer || !((Object)(object)owner.TargetingSystem != (Object)null) || !owner.TargetingSystem.IsTargetable(val))
			{
				return null;
			}
			return val;
		}

		internal static void Release(ComboMotion source, Character owner, int hit)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00bb: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Character> hashSet = new HashSet<Character>();
			Vector3 centerPosition = owner.CenterPosition;
			Collider[] array = Physics.OverlapSphere(centerPosition, 3f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			Vector3 val3 = default(Vector3);
			foreach (Collider collider in array)
			{
				Character val = Victim(owner, collider);
				if (!((Object)(object)val == (Object)null) && !hashSet.Contains(val))
				{
					Vector3 val2 = val.CenterPosition - centerPosition;
					((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
					if (!(Mathf.Abs(val2.y) > 1.7f) && !(Vector3.Angle(((Component)owner).transform.forward, val3) > 75f) && !Physics.Linecast(centerPosition, val.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
					{
						hashSet.Add(val);
						bool flag = PhysicalContactHit.Apply((MonoBehaviour)(object)source, owner, val, 80f, ((Vector3)(ref val2)).normalized, 12f, blockable: true);
						RubroBleed.TryApply(owner, val, flag);
						RubroVisual.Burst(val.CenterPosition);
						Plugin.Log.LogMessage((object)("[ComboRubro] CONTACT:" + (hit + 1) + ";" + val.Name + (flag ? ";BLOCKED" : "")));
					}
				}
			}
			GameObject val4 = new GameObject("ComboRubro_Feixe_" + (hit + 1));
			val4.transform.position = centerPosition;
			val4.transform.rotation = Quaternion.LookRotation(((Component)owner).transform.forward, Vector3.up);
			val4.AddComponent<RubroWave>().Bind(owner, hashSet, hit);
			Plugin.Log.LogMessage((object)("[ComboRubro] RELEASE:" + (hit + 1) + "/4;straightBlade;diagonal=" + RubroRibbon.Angle(hit) + ";range10m;per-strike dedup"));
		}
	}
	public sealed class RubroWave : MonoBehaviour
	{
		private Character owner;

		private HashSet<Character> victims;

		private Vector3 direction;

		private float distance;

		private float age;

		private int mask;

		private int hit;

		internal void Bind(Character value, HashSet<Character> contacts, int index)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			owner = value;
			victims = new HashSet<Character>(contacts);
			Vector3 forward = ((Component)owner).transform.forward;
			direction = ((Vector3)(ref forward)).normalized;
			hit = index;
			mask = Global.GeneralEnvironmentMask | LayerMask.GetMask(new string[1] { "Hitbox" });
			RubroVisual.Blade(((Component)this).transform, index);
		}

		private void Update()
		{
			//IL_00a7: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				float deltaTime = Time.deltaTime;
				age += deltaTime;
				if (age > 1.5f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				float num = Mathf.Min(20f * deltaTime, 10f - distance);
				if (num <= 0f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 0.48f, mask, (QueryTriggerInteraction)2);
				Collider[] array2 = array;
				foreach (Collider collider in array2)
				{
					if (Wall(collider))
					{
						Impact(((Component)this).transform.position);
						return;
					}
				}
				array2 = array;
				foreach (Collider collider2 in array2)
				{
					Damage(collider2);
				}
				RaycastHit[] array3 = Physics.SphereCastAll(((Component)this).transform.position, 0.48f, direction, num, mask, (QueryTriggerInteraction)2);
				Array.Sort(array3, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
				RaycastHit[] array4 = array3;
				for (int i = 0; i < array4.Length; i++)
				{
					RaycastHit val = array4[i];
					if (Wall(((RaycastHit)(ref val)).collider))
					{
						Impact(((RaycastHit)(ref val)).point);
						return;
					}
					Damage(((RaycastHit)(ref val)).collider);
				}
				Transform transform = ((Component)this).transform;
				transform.position += direction * num;
				distance += num;
				if (distance >= 9.999f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private bool Wall(Collider collider)
		{
			if (!collider.isTrigger && (Global.GeneralEnvironmentMask & (1 << ((Component)collider).gameObject.layer)) != 0)
			{
				return (Object)(object)((Component)collider).GetComponentInParent<Character>() == (Object)null;
			}
			return false;
		}

		private void Damage(Collider collider)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			Character val = ComboAttack.Victim(owner, collider);
			if (!((Object)(object)val == (Object)null) && victims.Add(val))
			{
				DamageList val2 = val.ReceiveHit((Object)null, new DamageList((Types)2, 80f), direction, val.CenterPosition, 45f, 1f, owner, 8f, true);
				RubroBleed.TryApply(owner, val, val2 == null || val2.TotalDamage <= 0f);
				RubroVisual.Burst(val.CenterPosition);
				Plugin.Log.LogMessage((object)("[ComboRubro] WAVE:" + (hit + 1) + ";" + val.Name + ";80Decay/8impact;native extreme bleeding on valid hit"));
			}
		}

		private void Impact(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			RubroVisual.Burst(position);
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	internal static class ComboClip
	{
		internal const string Prefix = "ComboRubroHumanoid_";

		internal const float Duration = 4.3333335f;

		internal const string Hash = "CB7E019E8C8B371CBC3D26FAD171D46D45E83DC445C916122F9B4A3CC2EA0CEC";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_combo_rubro");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "CB7E019E8C8B371CBC3D26FAD171D46D45E83DC445C916122F9B4A3CC2EA0CEC")
					{
						throw new InvalidDataException("Compiled combo SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled combo bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexComboRubro_Heavy4");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 4.3333335f) > 0.001f)
				{
					throw new InvalidDataException("Expected official external Humanoid four-hit combo");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "ComboRubroHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	public sealed class ComboMotion : MonoBehaviour
	{
		private Character player;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private ComboTimeline clock;

		private bool nativeCast;

		private float normalized;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (ComboClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding)
				{
					return (Object)(object)player.Animator.avatar == (Object)(object)avatar;
				}
				return false;
			}
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				ComboClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			if (((Item)value).ItemID != 9106910 || !CanBegin)
			{
				return false;
			}
			try
			{
				lease.Acquire(ComboClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new ComboTimeline();
				nativeCast = false;
				normalized = 0f;
				Plugin.Log.LogMessage((object)("[ComboRubro] CAST;externalHeavy4;nativeAvatar=" + ((Object)avatar).name + ";28vigor/10s"));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && !((Object)(object)value != (Object)(object)skill) && !tail.NativeEnded)
			{
				tail.EndNative();
				Plugin.Log.LogMessage((object)("[ComboRubro] NATIVEEND;hits=" + clock.Released + ";retain override through blend-out"));
			}
		}

		private void LateUpdate()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				bool observed = tail.Observed;
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (!observed && tail.Observed)
				{
					Plugin.Log.LogMessage((object)"[ComboRubro] EXTERNALACTIVE;Human=True;AvatarUNCHANGED");
				}
				if (flag)
				{
					clock.Observe(normalized);
					int hit;
					while (clock.TryRelease(out hit))
					{
						try
						{
							if (!nativeCast)
							{
								if (!OwnCast)
								{
									Fail("Native receiver lost before cost");
									return;
								}
								NativeInvocation = true;
								nativeCast = true;
								((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
								NativeInvocation = false;
								if (!Active || !OwnCast)
								{
									return;
								}
							}
							ComboAttack.Release(this, player, hit);
						}
						catch (Exception ex)
						{
							Fail("RELEASEFAILED:" + ex);
							return;
						}
						finally
						{
							NativeInvocation = false;
						}
					}
				}
				if (tail.CanRestore)
				{
					Cancel("native blend-out complete");
				}
				else if (tail.TimedOut(4.3333335f))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("ComboRubroHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[ComboRubro] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			clock?.Cancel();
			bool active = Active;
			int num = clock?.Released ?? 0;
			skill = null;
			tail = null;
			clock = null;
			nativeCast = false;
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[ComboRubro] RESTORED;reason=" + reason + ";hits=" + num));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[ComboRubro] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal sealed class ComboTimeline
	{
		private float progress;

		private int next;

		private bool cancelled;

		internal int Released => next;

		internal static float StrikeAt(int hit)
		{
			return hit switch
			{
				0 => 6f / 65f, 
				1 => 7f / 26f, 
				2 => 11f / 26f, 
				3 => 77f / 130f, 
				_ => throw new ArgumentOutOfRangeException("hit"), 
			};
		}

		internal void Observe(float normalized)
		{
			if (float.IsNaN(normalized) || float.IsInfinity(normalized) || normalized < 0f)
			{
				throw new ArgumentOutOfRangeException("normalized");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, Math.Min(normalized, 1f));
			}
		}

		internal bool TryRelease(out int hit)
		{
			hit = -1;
			if (cancelled || next >= 4 || progress < StrikeAt(next))
			{
				return false;
			}
			hit = next++;
			return true;
		}

		internal void Cancel()
		{
			cancelled = true;
		}
	}
	[BepInPlugin("codex.outward.combo.rubro", "Codex - Combo Rubro", "1.0.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.combo.rubro";

		public const int SkillId = 9106910;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = SkillIcon.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (Func<Sprite>)CarmVisual.CreateIcon, (Action<string>)Log.LogWarning);
			patches = new Harmony("codex.outward.combo.rubro");
			patches.PatchAll(typeof(Plugin).Assembly);
			RubroVisual.Paused = delegate
			{
				NetworkLevelLoader instance = NetworkLevelLoader.Instance;
				return instance != null && instance.IsGameplayPaused;
			};
			SL_Item.AddOnInstanceStartListener(9106910, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[ComboRubro] 1.0.8;treinador;cooldown100s;80 per strike/native bleed/approved animation unchanged");
		}

		private void Build()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				ComboClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				RubroVisual.Ensure();
				if ((Object)(object)ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Bleeding +") == (Object)null)
				{
					throw new InvalidOperationException("Native extreme bleeding prefab unavailable:Bleeding +");
				}
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106910) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106910);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106910;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Combo Rubro";
				((SL_Item)val2).Description = "Quatro cortes externos com feixes vermelhos diagonais.80 dano-base por corte:contato fisico/12 impacto ou feixe decomposicao/8 impacto,10m. Causa sangramento extremo nativo ao acertar,respeitando imunidades. Contato bloqueado nao aplica sangramento. Apenas um acerto por golpe em cada alvo.28vigor,100s recarga. Requer espada.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 28f;
				((SL_Skill)val2).Cooldown = 100f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[2]
				{
					default(WeaponType),
					(WeaponType)51
				};
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[ComboRubro] PRONTO:9106910;Combo Rubro;Human=True;four source strikes;28vigor/100s;visual USER APPROVED");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[ComboRubro] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106910)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			ComboMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								ComboMotion comboMotion = ((Component)value).GetComponent<ComboMotion>();
								if ((Object)(object)comboMotion == (Object)null)
								{
									try
									{
										comboMotion = ((Component)value).gameObject.AddComponent<ComboMotion>();
										comboMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)comboMotion != (Object)null)
										{
											Object.Destroy((Object)(object)comboMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[ComboRubro] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = comboMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			ComboMotion[] array = Object.FindObjectsOfType<ComboMotion>();
			foreach (ComboMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			RubroWave[] array2 = Object.FindObjectsOfType<RubroWave>();
			for (int i = 0; i < array2.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			}
			Harmony obj2 = patches;
			if (obj2 != null)
			{
				obj2.UnpatchAll("codex.outward.combo.rubro");
			}
			ComboClip.Dispose();
			RubroVisual.Release();
			SkillIcon.Release(icon);
			CarmVisual.Release();
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106910)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<ComboMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			ComboMotion component = ((Component)__instance).GetComponent<ComboMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106910)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter != null)
				{
					((Component)ownerCharacter).GetComponent<ComboMotion>()?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<ComboMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				ComboMotion comboMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<ComboMotion>() : null);
				if (((Item)__instance).ItemID == 9106910)
				{
					__result = comboMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && comboMotion != null && comboMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			ComboMotion component = ((Component)__instance).GetComponent<ComboMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class RubroBleed
	{
		internal const string Identifier = "Bleeding +";

		internal static bool TryApply(Character owner, Character target, bool rejectedHit)
		{
			if (rejectedHit || (Object)(object)owner == (Object)null || (Object)(object)target == (Object)null || !target.Alive || target.Invincible || (Object)(object)target.StatusEffectMngr == (Object)null)
			{
				return false;
			}
			ResourcesPrefabManager instance = ResourcesPrefabManager.Instance;
			StatusEffect val = ((instance != null) ? instance.GetStatusEffectPrefab("Bleeding +") : null);
			if ((Object)(object)val != (Object)null)
			{
				return (Object)(object)target.StatusEffectMngr.AddStatusEffect(val, owner) != (Object)null;
			}
			return false;
		}
	}
	internal static class RubroRibbon
	{
		internal readonly struct Vertex
		{
			internal readonly float X;

			internal readonly float Y;

			internal readonly float U;

			internal readonly float V;

			internal readonly float Alpha;

			internal Vertex(float x, float y, float u, float v, float alpha)
			{
				X = x;
				Y = y;
				U = u;
				V = v;
				Alpha = alpha;
			}
		}

		internal const int Segments = 28;

		internal const int Rows = 5;

		internal const float HalfLength = 1.35f;

		internal const float HalfWidth = 0.075f;

		internal static float Angle(int strike)
		{
			if (strike < 0 || strike > 3)
			{
				throw new ArgumentOutOfRangeException("strike");
			}
			return (strike % 2 == 0) ? 32 : (-32);
		}

		internal static Vertex[] Vertices()
		{
			Vertex[] array = new Vertex[145];
			for (int i = 0; i <= 28; i++)
			{
				float num = (float)i / 28f;
				float num2 = (float)Math.Pow(Math.Max(0.0, Math.Sin((double)num * Math.PI)), 0.55);
				float num3 = 0.075f * num2 * (1f + 0.06f * (float)Math.Sin(num * 29f));
				for (int j = 0; j < 5; j++)
				{
					float num4 = (float)j / 4f;
					float num5 = num4 * 2f - 1f;
					array[i * 5 + j] = new Vertex((num * 2f - 1f) * 1.35f, num5 * num3, num, num4, num2 * (float)Math.Pow(1f - Math.Abs(num5), 0.65));
				}
			}
			return array;
		}

		internal static int[] Triangles()
		{
			int[] array = new int[672];
			int num = 0;
			for (int i = 0; i < 28; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					int num2 = i * 5 + j;
					int num3 = num2 + 5;
					int num4 = num3 + 1;
					int num5 = num2 + 1;
					array[num++] = num2;
					array[num++] = num3;
					array[num++] = num5;
					array[num++] = num5;
					array[num++] = num3;
					array[num++] = num4;
				}
			}
			return array;
		}
	}
	internal static class RubroTexture
	{
		internal readonly struct Pixel
		{
			internal readonly float R;

			internal readonly float G;

			internal readonly float B;

			internal readonly float A;

			internal Pixel(float r, float g, float b, float a)
			{
				R = r;
				G = g;
				B = b;
				A = a;
			}
		}

		internal const int Width = 2048;

		internal const int Height = 512;

		private static float Clamp(float value)
		{
			return Math.Max(0f, Math.Min(1f, value));
		}

		internal static Pixel Sample(int x, int y)
		{
			if (x < 0 || x >= 2048 || y < 0 || y >= 512)
			{
				throw new ArgumentOutOfRangeException();
			}
			float num = (float)x / 2047f;
			float num2 = ((float)y - 255.5f) / 255.5f;
			float num3 = Clamp(1f - Math.Abs(num2));
			float num4 = 0.065f * (float)Math.Sin(num * 15f) + 0.025f * (float)Math.Sin(num * 41f);
			float num5 = (float)Math.Sin((double)((num2 - num4) * 18f + num * 7f) + 0.7 * Math.Sin(num * 25f));
			float num6 = (float)Math.Pow(Clamp((float)Math.Sin((num2 - num4) * 54f - num * 11f)), 8.0);
			float num7 = (float)Math.Pow(Clamp(1f - Math.Abs((float)Math.Sin((double)(num * 59f + num2 * 5f) + 0.45 * Math.Sin(num * 31f))) / 0.22f), 2.0);
			float num8 = Clamp((0.72f + 0.13f * num5 + 0.2f * num6) * (1f - num7 * (0.55f + 0.18f * Math.Abs(num2))));
			float a = (float)Math.Pow(num3, 0.7) * num8;
			return new Pixel(0.5f + 0.5f * num3, 0.1f + 0.75f * num3, 0.38f + 0.4f * num3, a);
		}
	}
	internal static class RubroVisual
	{
		private static Mesh ribbon;

		private static Material bladeMaterial;

		private static Material sparkMaterial;

		private static Texture2D bladeTexture;

		private static Texture2D sparkTexture;

		internal static Func<bool> Paused;

		internal static void Ensure()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01be: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Expected O, but got Unknown
			if ((Object)(object)ribbon != (Object)null)
			{
				return;
			}
			Shader val = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Red blade particle shader unavailable");
			}
			if (SystemInfo.maxTextureSize < 2048)
			{
				throw new InvalidOperationException("2K red blade texture exceeds GPU texture limit:" + SystemInfo.maxTextureSize);
			}
			bladeTexture = new Texture2D(2048, 512, (TextureFormat)4, true)
			{
				name = "Rubro_Estrias_Fissuras_2K",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)2,
				anisoLevel = 2
			};
			Color32[] array = (Color32[])(object)new Color32[1048576];
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 2048; j++)
				{
					RubroTexture.Pixel pixel = RubroTexture.Sample(j, i);
					array[i * 2048 + j] = Color32.op_Implicit(new Color(pixel.R, pixel.G, pixel.B, pixel.A));
				}
			}
			bladeTexture.SetPixels32(array);
			bladeTexture.Apply(true, true);
			sparkTexture = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "Rubro_Faisca_Suave",
				wrapMode = (TextureWrapMode)1
			};
			array = (Color32[])(object)new Color32[4096];
			for (int k = 0; k < 64; k++)
			{
				for (int l = 0; l < 64; l++)
				{
					Vector2 val2 = new Vector2(((float)l - 31.5f) / 31.5f, ((float)k - 31.5f) / 31.5f);
					float magnitude = ((Vector2)(ref val2)).magnitude;
					array[k * 64 + l] = Color32.op_Implicit(new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - magnitude), 2f)));
				}
			}
			sparkTexture.SetPixels32(array);
			sparkTexture.Apply(false, true);
			bladeMaterial = Material(val, (Texture)(object)bladeTexture, "Rubro_Lamina_Compartilhada");
			sparkMaterial = Material(val, (Texture)(object)sparkTexture, "Rubro_Faiscas_Compartilhadas");
			RubroRibbon.Vertex[] array2 = RubroRibbon.Vertices();
			Vector3[] array3 = (Vector3[])(object)new Vector3[array2.Length];
			Vector2[] array4 = (Vector2[])(object)new Vector2[array2.Length];
			Color[] array5 = (Color[])(object)new Color[array2.Length];
			for (int m = 0; m < array2.Length; m++)
			{
				RubroRibbon.Vertex vertex = array2[m];
				array3[m] = new Vector3(vertex.X, vertex.Y, 0f);
				array4[m] = new Vector2(vertex.U, vertex.V);
				float num = 1f - Mathf.Abs(vertex.V * 2f - 1f);
				array5[m] = Color.Lerp(new Color(0.65f, 0.025f, 0.12f, vertex.Alpha), new Color(1.12f, 0.21f, 0.25f, vertex.Alpha), num * num);
			}
			ribbon = new Mesh
			{
				name = "Rubro_Lamina_Reta_Afilada"
			};
			ribbon.vertices = array3;
			ribbon.uv = array4;
			ribbon.colors = array5;
			ribbon.triangles = RubroRibbon.Triangles();
			ribbon.RecalculateBounds();
		}

		private static Material Material(Shader shader, Texture texture, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(shader)
			{
				name = name,
				mainTexture = texture
			};
			if (val.HasProperty("_TintColor"))
			{
				val.SetColor("_TintColor", Color.white);
			}
			return val;
		}

		private static Transform Layer(Transform parent, string name, Vector3 scale, float depth, float brightness)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localScale = scale;
			val.transform.localPosition = new Vector3(0f, 0f, depth);
			val.AddComponent<MeshFilter>().sharedMesh = ribbon;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = bladeMaterial;
			MaterialPropertyBlock val2 = new MaterialPropertyBlock();
			val2.SetColor("_TintColor", new Color(brightness, brightness, brightness, 1f));
			val2.SetColor("_Color", new Color(brightness, brightness, brightness, 1f));
			((Renderer)obj).SetPropertyBlock(val2);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return val.transform;
		}

		internal static void Blade(Transform parent, int strike)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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)
			Ensure();
			GameObject val = new GameObject("Lamina_Rubra_Reta");
			val.transform.SetParent(parent, false);
			val.transform.localRotation = Quaternion.Euler(0f, 0f, RubroRibbon.Angle(strike));
			Transform halo = Layer(val.transform, "Borda_Rubra", new Vector3(1.04f, 3.4f, 1f), -0.02f, 0.23f);
			Layer(val.transform, "Nucleo_Estriado", Vector3.one, 0.02f, 0.62f);
			ParticleSystem particles = Particles(val.transform, burst: false);
			GameObject val2 = new GameObject("Rastro_Curto");
			val2.transform.SetParent(parent, false);
			TrailRenderer val3 = val2.AddComponent<TrailRenderer>();
			((Renderer)val3).sharedMaterial = sparkMaterial;
			val3.time = 0.12f;
			val3.minVertexDistance = 0.08f;
			val3.widthMultiplier = 0.11f;
			val3.numCapVertices = 2;
			val3.widthCurve = AnimationCurve.Linear(0f, 1f, 1f, 0f);
			val3.colorGradient = Fade();
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
			val.AddComponent<RubroBladeFx>().Bind(halo, particles, val3);
		}

		internal static void Burst(Vector3 point)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Rubro_Impacto_Faiscas");
			val.transform.position = point;
			Particles(val.transform, burst: true);
			Object.Destroy((Object)val, 0.65f);
		}

		private static Gradient Fade()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_001e: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(1f, 0.08f, 0.13f), 0f),
				new GradientColorKey(new Color(0.4f, 0f, 0.025f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.8f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}

		private static ParticleSystem Particles(Transform parent, bool burst)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(burst ? "Estilhacos_Rubros" : "Faiscas_Alongadas");
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = !burst;
			((MainModule)(ref main)).duration = 0.5f;
			((MainModule)(ref main)).maxParticles = 48;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.13f, burst ? 0.32f : 0.23f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.022f, burst ? 0.075f : 0.05f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(burst ? 1.2f : 0.15f, burst ? 3.5f : 0.6f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(1.2f, 0.035f, 0.08f, 0.9f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(burst ? 0.12f : 0f);
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit((float)((!burst) ? 72 : 0));
			if (burst)
			{
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)18)
				});
			}
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)((!burst) ? 5 : 0);
			((ShapeModule)(ref shape)).radius = 0.06f;
			((ShapeModule)(ref shape)).scale = (Vector3)(burst ? Vector3.one : new Vector3(2.4f, 0.05f, 0.02f));
			if (!burst)
			{
				((ShapeModule)(ref shape)).rotation = new Vector3(0f, 180f, 0f);
			}
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(Fade());
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = sparkMaterial;
			component.renderMode = (ParticleSystemRenderMode)1;
			component.lengthScale = 2f;
			component.velocityScale = 0.15f;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			val2.Play();
			return val2;
		}

		internal static void Release()
		{
			RubroBladeFx[] array = Object.FindObjectsOfType<RubroBladeFx>();
			for (int i = 0; i < array.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array[i]).gameObject);
			}
			Object[] array2 = (Object[])(object)new Object[5]
			{
				(Object)ribbon,
				(Object)bladeMaterial,
				(Object)sparkMaterial,
				(Object)bladeTexture,
				(Object)sparkTexture
			};
			foreach (Object val in array2)
			{
				if (val != (Object)null)
				{
					Object.Destroy(val);
				}
			}
			ribbon = null;
			bladeMaterial = (sparkMaterial = null);
			bladeTexture = (sparkTexture = null);
			Paused = null;
		}
	}
	public sealed class RubroBladeFx : MonoBehaviour
	{
		private Transform glow;

		private ParticleSystem sparks;

		private TrailRenderer trail;

		private float age;

		private bool paused;

		internal void Bind(Transform halo, ParticleSystem particles, TrailRenderer tail)
		{
			glow = halo;
			sparks = particles;
			trail = tail;
		}

		private void Update()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			bool flag = RubroVisual.Paused?.Invoke() ?? false;
			if (flag != paused)
			{
				paused = flag;
				if (flag)
				{
					sparks.Pause();
				}
				else
				{
					sparks.Play();
				}
				trail.emitting = !flag;
			}
			if (!flag)
			{
				age += Time.deltaTime;
				float num = 1f + 0.08f * Mathf.Sin(age * 31f);
				glow.localScale = new Vector3(1.04f, 3.4f * num, 1f);
			}
		}
	}
}
namespace CodexCorteCarmesim
{
	public static class CarmVisual
	{
		private static Material _material;

		private static Texture2D _sprite;

		private static Texture2D _icon;

		private static Mesh _crescent;

		private static Sprite _iconSprite;

		private static void Ensure()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_material != (Object)null)
			{
				return;
			}
			_sprite = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				name = "Carm_GotaSuave"
			};
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					Vector2 val = new Vector2(((float)j - 63.5f) / 63.5f, ((float)i - 63.5f) / 63.5f);
					float magnitude = ((Vector2)(ref val)).magnitude;
					array[i * 128 + j] = new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - magnitude), 2f));
				}
			}
			_sprite.SetPixels(array);
			_sprite.Apply(false, true);
			((Texture)_sprite).wrapMode = (TextureWrapMode)1;
			Shader obj = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("Shader de particulas ausente");
			}
			_material = new Material(obj)
			{
				name = "Carm_VFX_Compartilhado",
				mainTexture = (Texture)(object)_sprite
			};
			if (_material.HasProperty("_TintColor"))
			{
				_material.SetColor("_TintColor", Color.white);
			}
			Vector3[] array2 = (Vector3[])(object)new Vector3[130];
			Vector2[] array3 = (Vector2[])(object)new Vector2[array2.Length];
			Color[] array4 = (Color[])(object)new Color[array2.Length];
			int[] array5 = new int[384];
			for (int k = 0; k <= 64; k++)
			{
				float num = (float)k / 64f;
				float num2 = Mathf.Lerp(-128f, 128f, num) * ((float)Math.PI / 180f);
				float num3 = 0.12f * Mathf.Pow(Mathf.Sin(num * (float)Math.PI), 0.6f);
				float num4 = 0.025f * Mathf.Sin((float)k * 1.9f) * Mathf.Sin(num * (float)Math.PI);
				for (int l = 0; l < 2; l++)
				{
					float num5 = 1f + ((l == 0) ? (0f - num3) : num3) + num4;
					int num6 = k * 2 + l;
					array2[num6] = new Vector3(Mathf.Cos(num2) * num5 * 0.9f - 0.25f, Mathf.Sin(num2) * num5 * 0.85f, 0f);
					array3[num6] = new Vector2(0.5f, (l == 0) ? 0.32f : 0.68f);
					array4[num6] = ((l == 0) ? new Color(1f, 0.1f, 0.2f, 1f) : new Color(0.5f, 0f, 0.03f, 0.65f));
				}
				if (k < 64)
				{
					int num7 = k * 2;
					int num8 = k * 6;
					array5[num8] = num7;
					array5[num8 + 1] = num7 + 1;
					array5[num8 + 2] = num7 + 2;
					array5[num8 + 3] = num7 + 1;
					array5[num8 + 4] = num7 + 3;
					array5[num8 + 5] = num7 + 2;
				}
			}
			_crescent = new Mesh
			{
				name = "Carm_Arco_128tri"
			};
			_crescent.vertices = array2;
			_crescent.uv = array3;
			_crescent.colors = array4;
			_crescent.triangles = array5;
			_crescent.RecalculateBounds();
		}

		public static void Wave(Transform parent)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			for (int i = 0; i < 3; i++)
			{
				GameObject val = new GameObject("Arco_Camada_" + i);
				val.transform.SetParent(parent, false);
				val.transform.localScale = Vector3.one * (1f + (float)i * 0.13f);
				val.transform.localPosition = new Vector3(0f, 0f, -0.035f * (float)i);
				val.AddComponent<MeshFilter>().sharedMesh = _crescent;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = _material;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)obj).receiveShadows = false;
			}
			Particles(parent, burst: false);
		}

		public static void Burst(Vector3 point)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Carm_Impacto");
			val.transform.position = point;
			Particles(val.transform, burst: true);
			Object.Destroy((Object)val, 1.1f);
		}

		private static void Particles(Transform parent, bool burst)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(burst ? "Gotas_Impacto" : "Gotas_Rastro");
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = !burst;
			((MainModule)(ref main)).duration = 0.6f;
			((MainModule)(ref main)).maxParticles = 80;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.22f, 0.55f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.04f, 0.17f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(burst ? 1.2f : 0.2f, burst ? 4f : 0.8f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(1f, 0.04f, 0.12f, 0.8f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(burst ? 0.25f : 0.02f);
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit((float)((!burst) ? 72 : 0));
			if (burst)
			{
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)28)
				});
			}
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = (burst ? 0.12f : 0.52f);
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(1f, 0.15f, 0.3f), 0f),
				new GradientColorKey(new Color(0.3f, 0f, 0.02f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.85f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = _material;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			val2.Play();
		}

		public static Sprite CreateIcon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			if ((Object)(object)_iconSprite != (Object)null)
			{
				return _iconSprite;
			}
			_icon = new Texture2D(256, 256, (TextureFormat)4, false)
			{
				name = "CorteCarmesim_Icon"
			};
			Color[] array = (Color[])(object)new Color[65536];
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num = ((float)j - 127.5f) / 127.5f;
					float num2 = ((float)i - 127.5f) / 127.5f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Atan2(num2, num);
					float num5 = Mathf.Exp(0f - Mathf.Pow((num3 - 0.63f) * 28f, 2f)) * Mathf.Clamp01(1f - Mathf.Abs(num4) / 2.35f);
					float num6 = Mathf.Exp(0f - Mathf.Pow((num3 - 0.63f) * 9f, 2f)) * Mathf.Clamp01(1f - Mathf.Abs(num4) / 2.7f);
					float num7 = Mathf.Exp(0f - Mathf.Pow((num2 - num) * 45f, 2f)) * (float)((num3 < 0.72f) ? 1 : 0);
					float num8 = Mathf.Clamp01((1f - num3) * 14f);
					array[i * 256 + j] = new Color(0.06f + num5 * 0.94f + num6 * 0.35f + num7 * 0.65f, 0.018f + num7 * 0.38f + num5 * 0.07f, 0.03f + num7 * 0.4f + num5 * 0.15f, num8);
				}
			}
			_icon.SetPixels(array);
			_icon.Apply(false, true);
			_iconSprite = Sprite.Create(_icon, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
			Object.DontDestroyOnLoad((Object)(object)_icon);
			Object.DontDestroyOnLoad((Object)(object)_iconSprite);
			return _iconSprite;
		}

		public static void Release()
		{
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
			if ((Object)(object)_sprite != (Object)null)
			{
				Object.Destroy((Object)(object)_sprite);
			}
			if ((Object)(object)_crescent != (Object)null)
			{
				Object.Destroy((Object)(object)_crescent);
			}
			if ((Object)(object)_icon != (Object)null)
			{
				Object.Destroy((Object)(object)_icon);
			}
			if ((Object)(object)_iconSprite != (Object)null)
			{
				Object.Destroy((Object)(object)_iconSprite);
			}
			_material = null;
			_sprite = null;
			_crescent = null;
			_icon = null;
			_iconSprite = null;
		}
	}
}

BepInEx/plugins/Codex_Fenda_Hostil/CodexFendaHostil.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using CodexColossoFloresta;
using CodexCombat;
using CodexFendaHostil;
using CodexGolemExterno;
using CodexLoboGelo;
using CodexLobosElementais;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexFendaHostil
{
	internal sealed class DeathLoot : MonoBehaviour
	{
		private static readonly Random Random = new Random();

		private readonly DeathDropGate _gate = new DeathDropGate();

		private Character _body;

		private MonsterKind _kind;

		private string _lot;

		private Vector3 _deathPosition;

		private Vector3 _deathForward;

		private bool Ready
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name == "CierzoTutorial" && (Object)(object)NetworkLevelLoader.Instance != (Object)null)
				{
					return NetworkLevelLoader.Instance.IsOverallLoadingDone;
				}
				return false;
			}
		}

		private bool Dead
		{
			get
			{
				if ((Object)(object)_body != (Object)null && (Object)(object)_body.Stats != (Object)null && !_body.Alive)
				{
					return _body.Stats.CurrentHealth <= 0f;
				}
				return false;
			}
		}

		private bool Authority => !PhotonNetwork.isNonMasterClientInRoom;

		internal void Initialize(Character body, MonsterKind kind, string lot)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			_body = body;
			_kind = kind;
			_lot = lot;
			_gate.Arm((Object)(object)body != (Object)null && body.Alive);
			if ((Object)(object)body != (Object)null)
			{
				body.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(Died));
			}
			Plugin.Report(_lot, "DROP ARMADO:uma roupa nativa20% +uma arma custom20%,independentes;max2 por morte real.");
		}

		private void Update()
		{
			if (Dead)
			{
				Died();
			}
		}

		private void Died()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (_gate.TryBegin(Dead, Authority, Ready))
			{
				_deathPosition = ((Component)this).transform.position;
				_deathForward = ((Component)this).transform.forward;
				((MonoBehaviour)this).StartCoroutine(Drop());
			}
		}

		private int[] Plan()
		{
			Func<int, bool> exists = (int id) => (Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(id) != (Object)null;
			int[] array = LootPolicy.Available(LootPolicy.Armor(_kind), exists);
			int[] array2 = LootPolicy.Available(LootPolicy.CustomWeapons, exists);
			if (array.Length != 3 || array2.Length != 5)
			{
				Plugin.Report(_lot, "DROP AVISO:prefabs disponiveis roupa=" + array.Length + "/3,armas=" + array2.Length + "/5;ausentes nunca gerados.");
			}
			return LootPolicy.Roll(array, array2, Random.NextDouble(), (array.Length != 0) ? Random.Next(array.Length) : 0, Random.NextDouble(), (array2.Length != 0) ? Random.Next(array2.Length) : 0);
		}

		private unsafe IEnumerator Drop()
		{
			yield return null;
			float deadline = Time.realtimeSinceStartup + 15f;
			int[] rewards = null;
			while (_gate.Pending && Dead && Authority && Ready && Time.realtimeSinceStartup < deadline)
			{
				if ((Object)(object)ItemManager.Instance != (Object)null && ResourcesPrefabManager.Instance != null)
				{
					if (rewards == null)
					{
						try
						{
							rewards = Plan();
						}
						catch (Exception ex)
						{
							Plugin.Report(_lot, "DROP PLANO FALHOU,sem rerrolar:" + ex);
							_gate.Cancel();
						}
						if (!_gate.Pending)
						{
							yield break;
						}
						if (rewards.Length == 0)
						{
							_gate.TryCommit(Dead, Authority, Ready);
							Plugin.Report(_lot, "DROP SORTEIO:nenhum item nesta morte (roupa20%/arma20%).");
							yield break;
						}
						Plugin.Report(_lot, "DROP SORTEIO:" + string.Join(",", rewards) + ";plano fixo,sem nova rolagem.");
					}
					if (TryPositions(rewards.Length, out var positions))
					{
						if (!_gate.TryCommit(Dead, Authority, Ready))
						{
							yield break;
						}
						for (int i = 0; i < rewards.Length; i++)
						{
							try
							{
								Item val = ItemManager.Instance.GenerateItemNetwork(rewards[i]);
								if ((Object)(object)val == (Object)null)
								{
									throw new InvalidOperationException("Item generation returned null:" + rewards[i]);
								}
								val.IsPickable = true;
								val.ForceNonSavable = false;
								val.ChangeParent((Transform)null, positions[i], Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y, 90f));
								val.ResetTargetMove();
								val.SetForceSyncPos();
								string lot = _lot;
								string[] obj = new string[7]
								{
									"DROP OK:item=",
									rewards[i].ToString(),
									";UID=",
									val.UID,
									";pos=",
									null,
									null
								};
								Vector3 val2 = positions[i];
								obj[5] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
								obj[6] = ";nativo/coletavel;uma copia.";
								Plugin.Report(lot, string.Concat(obj));
							}
							catch (Exception ex2)
							{
								Plugin.Report(_lot, "DROP FALHOU item=" + rewards[i] + ";nao repetir geracao:" + ex2);
							}
						}
						yield break;
					}
				}
				yield return (object)new WaitForSeconds(0.25f);
			}
			if (_gate.Pending)
			{
				Plugin.Report(_lot, "DROP CANCELADO:sem apoio/servicos ou cena/autoridade mudou;sem item flutuante.");
			}
			_gate.Cancel();
		}

		private bool TryPositions(int count, out Vector3[] positions)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			positions = (Vector3[])(object)new Vector3[count];
			for (int i = 0; i < count; i++)
			{
				bool flag = false;
				for (int j = 0; j < 8; j++)
				{
					Vector3 forward = Quaternion.Euler(0f, (float)(j * 45 + i * 90), 0f) * _deathForward;
					if (!MarshDropGround.TryLootPoint(_deathPosition, forward, Global.GeneralEnvironmentMask, out var position))
					{
						continue;
					}
					bool flag2 = false;
					for (int k = 0; k < i; k++)
					{
						if (Vector3.Distance(position, positions[k]) < 0.8f)
						{
							flag2 = true;
						}
					}
					if (!flag2)
					{
						positions[i] = position;
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					return false;
				}
			}
			return true;
		}

		internal void Cancel()
		{
			_gate.Cancel();
			((MonoBehaviour)this).StopAllCoroutines();
		}

		private void OnDestroy()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Cancel();
			if ((Object)(object)_body != (Object)null)
			{
				Character body = _body;
				body.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(Died));
			}
		}
	}
	internal static class EncounterGround
	{
		internal static bool IsGround(Collider c)
		{
			if ((Object)(object)c != (Object)null && c.enabled && !c.isTrigger && ((Object)c).name.IndexOf("water", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return ((Object)c).name.IndexOf("agua", StringComparison.OrdinalIgnoreCase) < 0;
			}
			return false;
		}

		internal static bool Floor(Vector3 hint, int mask, out Vector3 surface, out Collider floor)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			surface = hint;
			floor = null;
			RaycastHit[] array = Physics.RaycastAll(new Ray(hint + Vector3.up * 6f, Vector3.down), 14f, mask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (IsGround(((RaycastHit)(ref val)).collider) && !(((RaycastHit)(ref val)).normal.y < 0.75f) && !(Mathf.Abs(((RaycastHit)(ref val)).point.y - hint.y) > 4f) && ((Object)(object)floor == (Object)null || Mathf.Abs(((RaycastHit)(ref val)).point.y - hint.y) < Mathf.Abs(surface.y - hint.y)))
				{
					surface = ((RaycastHit)(ref val)).point;
					floor = ((RaycastHit)(ref val)).collider;
				}
			}
			return (Object)(object)floor != (Object)null;
		}

		internal static bool Resolve(EncounterLot lot, int mask, IList<Vector3> occupied, out Vector3 surface)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			surface = lot.Point;
			Vector3[] array = EncounterLayout.Candidates(lot.Point);
			foreach (Vector3 val in array)
			{
				if (!EncounterLayout.SpawnAllowed(val) || !Floor(val, mask, out var surface2, out var floor))
				{
					continue;
				}
				bool flag = false;
				foreach (Vector3 item in occupied)
				{
					if (EncounterLayout.FlatDistance(surface2, item) < 35f)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
				Collider[] array2 = Physics.OverlapCapsule(surface2 + Vector3.up * lot.Bottom, surface2 + Vector3.up * lot.Top, lot.Radius, mask, (QueryTriggerInteraction)1);
				foreach (Collider val2 in array2)
				{
					if (!((Object)(object)val2 == (Object)(object)floor))
					{
						Bounds bounds = val2.bounds;
						if (!(((Bounds)(ref bounds)).max.y < surface2.y + 0.15f))
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					continue;
				}
				Vector3[] array3 = (Vector3[])(object)new Vector3[4]
				{
					Vector3.forward,
					Vector3.back,
					Vector3.left,
					Vector3.right
				};
				foreach (Vector3 val3 in array3)
				{
					if (!Floor(surface2 + val3 * lot.Radius, mask, out var surface3, out var _) || Mathf.Abs(surface3.y - surface2.y) > 0.35f)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					surface = surface2;
					return true;
				}
			}
			return false;
		}
	}
	internal enum MonsterKind
	{
		Stone,
		Fire,
		Ice,
		Forest
	}
	internal sealed class EncounterLot
	{
		internal readonly string Id;

		internal readonly MonsterKind Kind;

		internal readonly Vector3 Point;

		internal readonly bool Inside;

		internal float Health => (Kind == MonsterKind.Stone) ? 200 : ((Kind == MonsterKind.Fire) ? 180 : ((Kind == MonsterKind.Ice) ? 210 : 600));

		internal float Radius
		{
			get
			{
				if (Kind != MonsterKind.Forest)
				{
					if (Kind != MonsterKind.Stone)
					{
						return 1.35f;
					}
					return 0.8f;
				}
				return 1.7f;
			}
		}

		internal float Bottom
		{
			get
			{
				if (Kind != MonsterKind.Forest)
				{
					if (Kind != MonsterKind.Stone)
					{
						return 0.55f;
					}
					return 0.8f;
				}
				return 0.95f;
			}
		}

		internal float Top
		{
			get
			{
				if (Kind != MonsterKind.Forest)
				{
					if (Kind != MonsterKind.Stone)
					{
						return 0.85f;
					}
					return 2f;
				}
				return 3.85f;
			}
		}

		internal float Leash => (Kind == MonsterKind.Stone) ? 40 : ((Kind == MonsterKind.Forest) ? 10 : 12);

		internal EncounterLot(string id, MonsterKind kind, float x, float y, float z, bool inside = false)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Id = id;
			Kind = kind;
			Point = new Vector3(x, y, z);
			Inside = inside;
		}
	}
	internal static class EncounterLayout
	{
		internal static readonly EncounterLot[] Lots = new EncounterLot[12]
		{
			new EncounterLot("ruina_oeste", MonsterKind.Ice, 895f, 255f, 1706.7f, inside: true),
			new EncounterLot("praca", MonsterKind.Stone, 938f, 255f, 1728.7f, inside: true),
			new EncounterLot("ruina_norte", MonsterKind.Fire, 914f, 255f, 1769.7f, inside: true),
			new EncounterLot("campo_sudeste", MonsterKind.Stone, 1023f, 255f, 1650.7f),
			new EncounterLot("campo_oeste", MonsterKind.Fire, 833f, 255f, 1685.7f),
			new EncounterLot("campo_noroeste", MonsterKind.Ice, 838f, 255f, 1792.7f),
			new EncounterLot("campo_nordeste", MonsterKind.Forest, 1018f, 255f, 1812.7f),
			new EncounterLot("campo_leste", MonsterKind.Fire, 1108f, 255f, 1735.7f),
			new EncounterLot("campo_oeste_distante", MonsterKind.Stone, 723f, 255f, 1742.7f),
			new EncounterLot("campo_sudoeste", MonsterKind.Ice, 733f, 255f, 1620.7f),
			new EncounterLot("campo_noroeste_distante", MonsterKind.Forest, 623f, 255f, 1820.7f),
			new EncounterLot("campo_leste_distante", MonsterKind.Fire, 1198f, 255f, 1645.7f)
		};

		internal static readonly Vector3 Portal = new Vector3(933f, 255f, 1696.7f);

		internal static readonly Vector3 Arrival = new Vector3(933f, 255f, 1691.7f);

		internal const float SafeRadius = 12f;

		internal const float MinSpacing = 35f;

		internal const float Adjustment = 6f;

		internal static bool Safe(Vector3 p)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!(FlatDistance(p, Portal) < 12f))
			{
				return FlatDistance(p, Arrival) < 12f;
			}
			return true;
		}

		internal static float FlatDistance(Vector3 a, Vector3 b)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			a.y = 0f;
			b.y = 0f;
			return Vector3.Distance(a, b);
		}

		internal static bool SpawnAllowed(Vector3 p)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (FlatDistance(p, Portal) >= 26f)
			{
				return FlatDistance(p, Arrival) >= 26f;
			}
			return false;
		}

		internal static Vector3[] Candidates(Vector3 center)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[25];
			array[0] = center;
			for (int i = 1; i <= 3; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					float num = (float)j * (float)Math.PI / 4f;
					array[1 + (i - 1) * 8 + j] = center + new Vector3(Mathf.Cos(num) * (float)i * 2f, 0f, Mathf.Sin(num) * (float)i * 2f);
				}
			}
			return array;
		}
	}
	internal static class LootPolicy
	{
		internal const double Chance = 0.2;

		private static readonly int[][] Clothes = new int[4][]
		{
			new int[3] { 3100140, 3100141, 3100142 },
			new int[3] { 3000210, 3000211, 3000212 },
			new int[3] { 3100090, 3100091, 3100092 },
			new int[3] { 3000040, 3000041, 3000043 }
		};

		internal static readonly int[] CustomWeapons = new int[5] { 9000006, 9000007, 9000008, 9000011, 9000012 };

		internal static int[] Armor(MonsterKind kind)
		{
			return (int[])Clothes[(int)kind].Clone();
		}

		internal static int[] Available(int[] pool, Func<int, bool> exists)
		{
			List<int> list = new List<int>();
			foreach (int num in pool)
			{
				if (exists(num))
				{
					list.Add(num);
				}
			}
			return list.ToArray();
		}

		internal static int[] Roll(int[] armor, int[] weapons, double armorRoll, int armorChoice, double weaponRoll, int weaponChoice)
		{
			if (armorRoll < 0.0 || armorRoll > 1.0 || weaponRoll < 0.0 || weaponRoll > 1.0)
			{
				throw new ArgumentOutOfRangeException("Probability roll");
			}
			List<int> list = new List<int>(2);
			if (armorRoll < 0.2 && armor.Length != 0)
			{
				list.Add(armor[armorChoice]);
			}
			if (weaponRoll < 0.2 && weapons.Length != 0)
			{
				list.Add(weapons[weaponChoice]);
			}
			return list.ToArray();
		}
	}
	internal static class MarshDropGround
	{
		internal static bool TryLootPoint(Vector3 death, Vector3 forward, int mask, out Vector3 position)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0163: 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)
			forward.y = 0f;
			forward = ((((Vector3)(ref forward)).sqrMagnitude < 0.01f) ? Vector3.forward : ((Vector3)(ref forward)).normalized);
			Vector3 val = Vector3.Cross(Vector3.up, forward);
			Vector3[] array = (Vector3[])(object)new Vector3[5]
			{
				val * 1.5f,
				-val * 1.5f,
				forward * 1.5f,
				-forward * 1.5f,
				Vector3.zero
			};
			foreach (Vector3 val2 in array)
			{
				if (!EncounterGround.Floor(death + val2, mask, out var surface, out var floor) || Mathf.Abs(surface.y - death.y) > 3f)
				{
					continue;
				}
				bool flag = false;
				Collider[] array2 = Physics.OverlapSphere(surface + Vector3.up * 0.4f, 0.35f, mask, (QueryTriggerInteraction)1);
				foreach (Collider val3 in array2)
				{
					if ((Object)(object)val3 != (Object)(object)floor)
					{
						Bounds bounds = val3.bounds;
						if (((Bounds)(ref bounds)).max.y > surface.y + 0.12f)
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					position = surface + Vector3.up * 0.2f;
					return true;
				}
			}
			position = death;
			return false;
		}
	}
	[BepInPlugin("codex.outward.fenda.hostil", "Codex - Vila da Fenda Hostil", "1.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Slot
		{
			internal EncounterLot Lot;

			internal SL_Character Template;

			internal Character Body;

			internal GameObject Actor;

			internal bool Complete;

			internal float Retry;

			internal float Warning;

			internal DeathLoot Loot;
		}

		internal static Plugin Instance;

		private readonly List<Slot> _slots = new List<Slot>();

		private readonly Dictionary<MonsterKind, AssetBundle> _bundles = new Dictionary<MonsterKind, AssetBundle>();

		private readonly HashSet<AssetBundle> _ownedBundles = new HashSet<AssetBundle>();

		private readonly Dictionary<MonsterKind, GameObject> _prefabs = new Dictionary<MonsterKind, GameObject>();

		private bool _creating;

		private bool _assetsReady;

		private int _generation;

		private float _scan;

		private void Awake()
		{
			Instance = this;
			EncounterLot[] lots = EncounterLayout.Lots;
			foreach (EncounterLot lot in lots)
			{
				_slots.Add(new Slot
				{
					Lot = lot
				});
			}
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += SceneLoaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			Report("Inicio", "v1.2.1;12 encontros na Fenda;spawn por proximidade135m.");
		}

		private void Load(MonsterKind kind, string bundleName, string asset)
		{
			AssetBundle val = null;
			foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
			{
				if ((Object)(object)allLoadedAssetBundle == (Object)null)
				{
					continue;
				}
				string[] allAssetNames = allLoadedAssetBundle.GetAllAssetNames();
				for (int i = 0; i < allAssetNames.Length; i++)
				{
					if (string.Equals(allAssetNames[i], asset, StringComparison.OrdinalIgnoreCase))
					{
						val = allLoadedAssetBundle;
						break;
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			bool flag = (Object)(object)val == (Object)null;
			if (flag)
			{
				val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), bundleName));
			}
			if ((Object)(object)val == (Object)null)
			{
				throw new IOException("Bundle ausente:" + bundleName);
			}
			GameObject val2 = val.LoadAsset<GameObject>(asset);
			if ((Object)(object)val2 == (Object)null)
			{
				if (flag)
				{
					val.Unload(true);
				}
				throw new IOException("Prefab ausente:" + asset);
			}
			_bundles.Add(kind, val);
			if (flag)
			{
				_ownedBundles.Add(val);
			}
			_prefabs.Add(kind, val2);
		}

		private bool EnsureAssets()
		{
			if (_assetsReady)
			{
				return true;
			}
			try
			{
				Load(MonsterKind.Stone, "externalstonegolem", "Assets/Generated/ExternalStoneGolem.prefab");
				Load(MonsterKind.Fire, "externalelementalwolf", "Assets/Generated/ExternalFireWolf.prefab");
				Load(MonsterKind.Ice, "externalicewolf", "Assets/Generated/ExternalIceWolf.prefab");
				Load(MonsterKind.Forest, "externalforestcolossus", "Assets/Generated/ExternalForestColossus.prefab");
				_assetsReady = true;
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				UnloadAssets();
				((Behaviour)this).enabled = false;
				return false;
			}
		}

		private void UnloadAssets()
		{
			_prefabs.Clear();
			foreach (AssetBundle ownedBundle in _ownedBundles)
			{
				if ((Object)(object)ownedBundle != (Object)null)
				{
					ownedBundle.Unload(true);
				}
			}
			_bundles.Clear();
			_ownedBundles.Clear();
			_assetsReady = false;
		}

		private void Prepare()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: 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_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			foreach (Slot slot in _slots)
			{
				if (slot.Template == null)
				{
					EncounterLot lot = slot.Lot;
					SL_Character val = new SL_Character
					{
						UID = "codex.character.fenda.hostil." + lot.Id,
						Name = ((lot.Kind == MonsterKind.Stone) ? "Guardiao da Fenda" : ((lot.Kind == MonsterKind.Fire) ? "Cao das Brasas" : ((lot.Kind == MonsterKind.Ice) ? "Lobo da Geada" : "Colosso da Floresta"))),
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						DestroyOnDeath = false,
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						Faction = (Factions)9,
						CharacterVisualsData = new VisualData(),
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = -1,
						Boots_ID = -1,
						Backpack_ID = -1,
						Health = lot.Health,
						HealthRegen = 0f,
						Protection = 0f,
						Barrier = 0f,
						ImpactResist = 100f,
						Damage_Resists = new float[9],
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false
					};
					((ContentTemplate)val).ApplyTemplate();
					slot.Template = val;
				}
			}
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "CierzoTutorial" || _creating || Time.realtimeSinceStartup < _scan || (Object)(object)CharacterManager.Instance == (Object)null || (Object)(object)NetworkLevelLoader.Instance == (Object)null || !NetworkLevelLoader.Instance.IsOverallLoadingDone || NetworkLevelLoader.Instance.IsGameplayPaused)
			{
				return;
			}
			_scan = Time.realtimeSinceStartup + 0.75f;
			bool flag = false;
			foreach (Slot slot in _slots)
			{
				if (!slot.Complete && (Object)(object)NearestPlayer(slot.Lot.Point, 135f, combat: false) != (Object)null)
				{
					flag = true;
					break;
				}
			}
			if (!flag || !EnsureAssets())
			{
				return;
			}
			foreach (Slot slot2 in _slots)
			{
				if (slot2.Template == null || slot2.Complete || Time.realtimeSinceStartup < slot2.Retry || (Object)(object)NearestPlayer(slot2.Lot.Point, 135f, combat: false) == (Object)null)
				{
					continue;
				}
				List<Vector3> list = new List<Vector3>();
				foreach (Slot slot3 in _slots)
				{
					if (slot3 != slot2 && (Object)(object)slot3.Actor != (Object)null)
					{
						list.Add(slot3.Actor.transform.position);
					}
				}
				if (!EncounterGround.Resolve(slot2.Lot, Global.GeneralEnvironmentMask, list, out var surface))
				{
					slot2.Retry = Time.realtimeSinceStartup + 5f;
					if (Time.realtimeSinceStartup >= slot2.Warning)
					{
						Report(slot2.Lot.Id, "AGUARDANDO piso/lote livre,sem deslocar props.");
						slot2.Warning = Time.realtimeSinceStartup + 30f;
					}
					continue;
				}
				((MonoBehaviour)this).StartCoroutine(Create(slot2, surface, _generation));
				break;
			}
		}

		private unsafe IEnumerator Create(Slot slot, Vector3 surface, int generation)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			_creating = true;
			try
			{
				slot.Body = slot.Template.Spawn(surface + Vector3.up * 0.04f, (string)null, (string)null);
				HideNative(slot);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			if ((Object)(object)slot.Body == (Object)null)
			{
				slot.Retry = Time.realtimeSinceStartup + 5f;
				_creating = false;
				yield break;
			}
			float until = Time.realtimeSinceStartup + 25f;
			while (generation == _generation && (Object)(object)slot.Body != (Object)null && !Ready(slot.Body) && Time.realtimeSinceStartup < until)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (generation != _generation)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)slot.Body == (Object)null || !Ready(slot.Body))
				{
					throw new InvalidOperationException("Receptor nao inicializou:" + slot.Lot.Id);
				}
				Quaternion val = Quaternion.Euler(0f, (surface.x + surface.z) % 360f, 0f);
				slot.Body.Teleport(surface + Vector3.up * 0.04f, val);
				slot.Body.Invincible = false;
				slot.Body.QuestInvicibility = false;
				slot.Body.QuestNonTargetable = false;
				slot.Body.Stats.SetHealth(slot.Lot.Health);
				slot.Actor = Object.Instantiate<GameObject>(_prefabs[slot.Lot.Kind], surface + Vector3.up * 0.04f, val);
				((Object)slot.Actor).name = "FendaHostil_" + slot.Lot.Id;
				switch (slot.Lot.Kind)
				{
				case MonsterKind.Stone:
					slot.Actor.AddComponent<StoneEnemy>().Initialize(slot.Body);
					break;
				case MonsterKind.Fire:
					slot.Actor.AddComponent<CodexLobosElementais.WolfEnemy>().Initialize(slot.Body);
					break;
				case MonsterKind.Ice:
					slot.Actor.AddComponent<CodexLoboGelo.WolfEnemy>().Initialize(slot.Body);
					break;
				case MonsterKind.Forest:
					slot.Actor.AddComponent<ForestEnemy>().Initialize(slot.Body);
					break;
				}
				slot.Loot = slot.Actor.AddComponent<DeathLoot>();
				slot.Loot.Initialize(slot.Body, slot.Lot.Kind, slot.Lot.Id);
				slot.Complete = true;
				string id = slot.Lot.Id;
				string[] obj = new string[7]
				{
					"PRONTO ",
					slot.Lot.Kind.ToString(),
					" pos=",
					null,
					null,
					null,
					null
				};
				Vector3 val2 = surface;
				obj[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
				obj[4] = " vida=";
				obj[5] = slot.Lot.Health.ToString();
				obj[6] = " roupa20%/arma20%.";
				Report(id, string.Concat(obj));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex2);
				ClearSlot(slot);
				slot.Retry = Time.realtimeSinceStartup + 10f;
			}
			_creating = false;
		}

		private static bool Ready(Character body)
		{
			if ((Object)(object)body.Stats != (Object)null && (Object)(object)body.Animator != (Object)null && body.Hitboxes != null)
			{
				return body.Hitboxes.Length != 0;
			}
			return false;
		}

		private static void HideNative(Slot slot)
		{
			switch (slot.Lot.Kind)
			{
			case MonsterKind.Stone:
				((Component)slot.Body).gameObject.AddComponent<CodexGolemExterno.InvisibleReceiver>();
				break;
			case MonsterKind.Fire:
				((Component)slot.Body).gameObject.AddComponent<CodexLobosElementais.InvisibleReceiver>();
				break;
			case MonsterKind.Ice:
				((Component)slot.Body).gameObject.AddComponent<CodexLoboGelo.InvisibleReceiver>();
				break;
			case MonsterKind.Forest:
				((Component)slot.Body).gameObject.AddComponent<CodexColossoFloresta.InvisibleReceiver>();
				break;
			}
		}

		internal static Character NearestPlayer(Vector3 point, float radius, bool combat)
		{
			//IL_0060: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return null;
			}
			Character result = null;
			float num = radius * radius;
			foreach (Character value in CharacterManager.Instance.Characters.Values)
			{
				if (!((Object)(object)value == (Object)null) && value.IsLocalPlayer && value.Alive && !(Mathf.Abs(((Component)value).transform.position.y - point.y) > 12f) && (!combat || !EncounterLayout.Safe(((Component)value).transform.position)))
				{
					Vector3 val = ((Component)value).transform.position - point;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = value;
					}
				}
			}
			return result;
		}

		internal static bool AllowsDamage(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return !EncounterLayout.Safe(point);
		}

		internal static void Report(string id, string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogMessage((object)("[FendaHostil:" + id + "] " + message));
			}
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
				if (((Scene)(ref scene)).name != "CierzoTutorial")
				{
					UnloadAssets();
				}
			}
		}

		private void ClearSlot(Slot slot)
		{
			if ((Object)(object)slot.Loot != (Object)null)
			{
				slot.Loot.Cancel();
			}
			if ((Object)(object)slot.Actor != (Object)null)
			{
				Object.Destroy((Object)(object)slot.Actor);
			}
			if ((Object)(object)slot.Body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(slot.Body);
			}
			slot.Actor = null;
			slot.Body = null;
			slot.Loot = null;
			slot.Complete = false;
		}

		private void Cleanup()
		{
			_generation++;
			((MonoBehaviour)this).StopAllCoroutines();
			foreach (Slot slot in _slots)
			{
				ClearSlot(slot);
				slot.Retry = 0f;
				slot.Warning = 0f;
			}
			_creating = false;
			_scan = 0f;
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= SceneLoaded;
			Cleanup();
			foreach (Slot slot in _slots)
			{
				if (slot.Template != null)
				{
					slot.Template.Unregister();
				}
			}
			UnloadAssets();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
}
namespace CodexColossoFloresta
{
	internal sealed class Plugin
	{
		internal static readonly Plugin Instance = new Plugin();

		internal static Character NearestPlayer(Vector3 p, float r)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return CodexFendaHostil.Plugin.NearestPlayer(p, r, r <= 40f);
		}

		internal void Message(string s)
		{
			CodexFendaHostil.Plugin.Report("Floresta", s);
		}
	}
	public static class ForestCombat
	{
		public const float Health = 600f;

		public const float SlamDamage = 36f;

		public const float SlamImpact = 70f;

		public const float RockDamage = 28f;

		public const float RockImpact = 32f;

		public const float StrikeRange = 3.8f;

		public static float StrikeDamage(int step)
		{
			return (step == 1) ? 22 : 26;
		}

		public static float StrikeImpact(int step)
		{
			return (step == 1) ? 28 : 38;
		}

		public static float HealedHealth(float health, float amount)
		{
			return Mathf.Min(600f, health + amount);
		}

		public static bool CanStrike(Vector3 origin, Vector3 forward, Vector3 feet, Vector3 center, int environment)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = feet - origin;
			if (Mathf.Abs(val.y) > 2.5f)
			{
				return false;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).magnitude <= 3.8f && Vector3.Angle(forward, val) <= 60f)
			{
				return !Physics.Linecast(origin + Vector3.up * 1.8f, center, environment, (QueryTriggerInteraction)1);
			}
			return false;
		}

		public static bool CanSlam(Vector3 origin, Vector3 feet, Vector3 center, int environment)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = feet - origin;
			if (Mathf.Abs(val.y) > 2.5f)
			{
				return false;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).magnitude <= 5f)
			{
				return !Physics.Linecast(origin + Vector3.up * 1.8f, center, environment, (QueryTriggerInteraction)1);
			}
			return false;
		}
	}
	internal sealed class InvisibleReceiver : MonoBehaviour
	{
		private readonly List<Renderer> renderers = new List<Renderer>();

		private float nextScan;

		private float started = -1f;

		private void LateUpdate()
		{
			if (started < 0f)
			{
				started = Time.unscaledTime;
			}
			if (Time.unscaledTime >= nextScan)
			{
				((Component)this).GetComponentsInChildren<Renderer>(true, renderers);
				nextScan = Time.unscaledTime + ((Time.unscaledTime - started < 4f) ? 0.15f : 1f);
			}
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null && renderer.enabled)
				{
					renderer.enabled = false;
				}
			}
		}
	}
	internal sealed class ForestEnemy : MonoBehaviour
	{
		private Character _body;

		private ForestMotor _motor;

		private ForestSlam _slam;

		private Transform _hand;

		private Collider[] _nativeColliders;

		private Rigidbody[] _rigidbodies;

		private Renderer[] _visual;

		private Hitbox _receiver;

		private SphereCollider _locking;

		private float _health;

		private float _report;

		private float _damageLogAt;

		private float _damageSinceLog;

		private float _nextVisibility;

		private readonly List<ForestRock> _rocks = new List<ForestRock>();

		private List<Character> _targets = new List<Character>();

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

		internal void Initialize(Character body)
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_015e: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Expected O, but got Unknown
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Expected O, but got Unknown
			_body = body;
			CharacterAI component = ((Component)body).GetComponent<CharacterAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			NavMeshAgent component2 = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			CharacterControl component3 = ((Component)body).GetComponent<CharacterControl>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			if ((Object)(object)body.CharacterController != (Object)null)
			{
				((Collider)body.CharacterController).enabled = false;
			}
			_nativeColliders = ((Component)body).GetComponentsInChildren<Collider>(true);
			Collider[] nativeColliders = _nativeColliders;
			for (int i = 0; i < nativeColliders.Length; i++)
			{
				nativeColliders[i].enabled = false;
			}
			_rigidbodies = ((Component)body).GetComponentsInChildren<Rigidbody>(true);
			Rigidbody[] rigidbodies = _rigidbodies;
			foreach (Rigidbody obj in rigidbodies)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			int num = LayerMask.NameToLayer("Hitbox");
			int num2 = LayerMask.NameToLayer("LockingPoints");
			if (num < 0 || num2 < 0 || (Global.LockingPointsMask & (1 << num2)) == 0)
			{
				throw new InvalidOperationException("Native damage/lock layers absent");
			}
			GameObject val = new GameObject("Colosso_ReceptorDano");
			val.transform.SetParent(((Component)body).transform, false);
			val.layer = num;
			CapsuleCollider obj2 = val.AddComponent<CapsuleCollider>();
			obj2.radius = 0.94f;
			obj2.height = 3.4f;
			obj2.center = Vector3.up * 1.7f;
			((Collider)obj2).isTrigger = true;
			_receiver = val.AddComponent<Hitbox>();
			_receiver.OwnerChar = body;
			_receiver.Melee = true;
			_receiver.Ranged = true;
			FieldInfo? field = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("Character.m_hitboxes");
			}
			field.SetValue(body, new Hitbox[1] { _receiver });
			GameObject val2 = new GameObject("Colosso_MiraNativa");
			val2.transform.SetParent(((Component)body).transform, false);
			val2.transform.localPosition = Vector3.up * 2f;
			val2.layer = num2;
			_locking = val2.AddComponent<SphereCollider>();
			_locking.radius = 0.18f;
			((Collider)_locking).isTrigger = true;
			LockingPoint obj3 = val2.AddComponent<LockingPoint>();
			obj3.OwnerChar = body;
			obj3.HideFlare = false;
			((Component)this).gameObject.layer = ((Component)body).gameObject.layer;
			CharacterController val3 = ((Component)this).gameObject.AddComponent<CharacterController>();
			ConfigureController(val3);
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>();
			foreach (Transform val4 in componentsInChildren)
			{
				if (((Object)val4).name == "RockAnchor")
				{
					_hand = val4;
				}
			}
			if ((Object)(object)_hand == (Object)null)
			{
				throw new InvalidOperationException("External hand anchor absent");
			}
			_visual = ((Component)this).GetComponentsInChildren<Renderer>();
			Renderer[] visual = _visual;
			for (int i = 0; i < visual.Length; i++)
			{
				visual[i].shadowCastingMode = (ShadowCastingMode)0;
			}
			_slam = ((Component)this).gameObject.AddComponent<ForestSlam>();
			_slam.Initialize(Global.GeneralEnvironmentMask);
			_motor = ((Component)this).gameObject.AddComponent<ForestMotor>();
			_motor.Initialize(((Component)this).GetComponentInChildren<Animation>(), val3, Global.GeneralEnvironmentMask);
			_motor.Target = delegate
			{
				//IL_0006: 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)
				Character val5 = Plugin.NearestPlayer(((Component)this).transform.position, 30f);
				return (!((Object)(object)val5 == (Object)null)) ? new Vector3?(((Component)val5).transform.position) : ((Vector3?)null);
			};
			_motor.Paused = Paused;
			_motor.Slam = Slam;
			_motor.Strike = Strike;
			_motor.Shoot = Shoot;
			_motor.Warning = _slam.Warn;
			_motor.Heal = Heal;
			_motor.RageChanged = _slam.SetRage;
			_motor.Trace = Plugin.Instance.Message;
			_health = body.Stats.CurrentHealth;
			body.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(Dead));
			Plugin.Instance.Message("ATIVO:modelo/rig CDmir externos;600HP,combo22/26/36,mira nativa camada" + num2 + ",IA e locomocao proprias.");
		}

		internal static void ConfigureController(CharacterController cc)
		{
			//IL_0017: 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)
			cc.radius = 0.85f;
			cc.height = 3.4f;
			cc.center = Vector3.up * 1.7f;
			cc.skinWidth = 0.025f;
			cc.stepOffset = 0.3f;
			cc.slopeLimit = 45f;
			cc.minMoveDistance = 0f;
		}

		private static bool Paused()
		{
			if (!((Object)(object)NetworkLevelLoader.Instance == (Object)null) && NetworkLevelLoader.Instance.IsOverallLoadingDone)
			{
				return NetworkLevelLoader.Instance.IsGameplayPaused;
			}
			return true;
		}

		private void Update()
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || (Object)(object)_motor == (Object)null)
			{
				return;
			}
			if (!_body.Alive)
			{
				Dead();
			}
			float currentHealth = _body.Stats.CurrentHealth;
			if (currentHealth < _health && !_motor.Dead)
			{
				float num = _health - currentHealth;
				_motor.Hurt(num);
				_damageSinceLog += num;
				if (Time.time >= _damageLogAt)
				{
					Plugin.Instance.Message("Dano recebido:" + _damageSinceLog + ";cambaleios=" + _motor.Staggers);
					_damageSinceLog = 0f;
					_damageLogAt = Time.time + 2f;
				}
			}
			_health = currentHealth;
			_motor.SetHealth(currentHealth);
			if (Time.time >= _nextVisibility)
			{
				bool flag = (Object)(object)Plugin.NearestPlayer(((Component)this).transform.position, 150f) != (Object)null;
				Renderer[] visual = _visual;
				foreach (Renderer val in visual)
				{
					if ((Object)(object)val != (Object)null && val.enabled != flag)
					{
						val.enabled = flag;
					}
				}
				_slam.SetVisible(flag);
				bool flag2 = flag || _motor.Phase != "Idle";
				if (((Behaviour)_motor).enabled != flag2)
				{
					((Behaviour)_motor).enabled = flag2;
				}
				_nextVisibility = Time.time + 0.25f;
			}
			_rocks.RemoveAll((ForestRock b) => (Object)(object)b == (Object)null);
			if (Time.time >= _report)
			{
				Plugin.Instance.Message("Estado=" + _motor.Phase + ";pos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString() + ";andou=" + _motor.DistanceWalked.ToString("F1") + "m;vida=" + currentHealth);
				_report = Time.time + 15f;
			}
		}

		private void Slam()
		{
			//IL_0062: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			if ((Object)(object)_body == (Object)null || !_body.Alive || _motor.Dead || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			_slam.Impact();
			_targets.Clear();
			_hit.Clear();
			CharacterManager.Instance.FindCharactersInRange(((Component)this).transform.position, 7f, ref _targets);
			foreach (Character target in _targets)
			{
				if (!((Object)(object)target == (Object)null) && target.IsLocalPlayer && target.Alive && !(Mathf.Abs(((Component)target).transform.position.y - ((Component)this).transform.position.y) > 8f) && CodexFendaHostil.Plugin.AllowsDamage(((Component)target).transform.position) && _hit.Add(target) && ForestCombat.CanSlam(((Component)this).transform.position, ((Component)target).transform.position, target.CenterPosition, Global.GeneralEnvironmentMask))
				{
					Vector3 val = ((Component)target).transform.position - ((Component)this).transform.position;
					val.y = 0f;
					target.ReceiveHit((Object)null, new DamageList((Types)0, 36f), ((Vector3)(ref val)).normalized, target.CenterPosition, 45f, 1f, _body, 70f, true);
					Plugin.Instance.Message("ABALO acertou " + target.Name + ":36fisico/70impacto,uma vez.");
				}
			}
		}

		private void Strike(int step)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0140: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || !_body.Alive || _motor.Dead || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			_slam.Chips(_hand.position, ((Component)this).transform.forward);
			_targets.Clear();
			_hit.Clear();
			CharacterManager.Instance.FindCharactersInRange(((Component)this).transform.position, 5f, ref _targets);
			foreach (Character target in _targets)
			{
				if (!((Object)(object)target == (Object)null) && target.IsLocalPlayer && target.Alive && !(Mathf.Abs(((Component)target).transform.position.y - ((Component)this).transform.position.y) > 8f) && CodexFendaHostil.Plugin.AllowsDamage(((Component)target).transform.position) && _hit.Add(target) && ForestCombat.CanStrike(((Component)this).transform.position, ((Component)this).transform.forward, ((Component)target).transform.position, target.CenterPosition, Global.GeneralEnvironmentMask))
				{
					Vector3 val = ((Component)target).transform.position - ((Component)this).transform.position;
					val.y = 0f;
					bool flag = PhysicalContactHit.Apply((MonoBehaviour)(object)this, _body, target, ForestCombat.StrikeDamage(step), ((Vector3)(ref val)).normalized, ForestCombat.StrikeImpact(step), blockable: true);
					Plugin.Instance.Message("COMBO golpe" + step + (flag ? " BLOQUEADO por " : " acertou ") + target.Name + ":" + ForestCombat.StrikeDamage(step) + "fisico/" + ForestCombat.StrikeImpact(step) + "impacto,uma vez.");
				}
			}
		}

		private void Shoot(Vector3 aim)
		{
			//IL_0043: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_body == (Object)null) && _body.Alive && !_motor.Dead && _rocks.Count < 2)
			{
				ForestRock rock = new GameObject("Colosso_Pedrada").AddComponent<ForestRock>();
				((Component)rock).transform.position = _hand.position + ((Component)this).transform.forward * 0.4f;
				_rocks.Add(rock);
				rock.Victim = IsVictim;
				rock.Hit = RockHit;
				rock.Paused = Paused;
				rock.Visible = () => (Object)(object)Plugin.NearestPlayer(((Component)rock).transform.position, 150f) != (Object)null;
				rock.Initialize(aim, Global.GeneralEnvironmentMask, 1 << LayerMask.NameToLayer("Hitbox"));
				Plugin.Instance.Message("ROCHA lancada:28fisico/32impacto,arco balistico8m/s,22m.");
			}
		}

		private bool IsVictim(Collider col)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Hitbox componentInParent = ((Component)col).GetComponentInParent<Hitbox>();
			Character val = (((Object)(object)componentInParent == (Object)null) ? null : componentInParent.OwnerChar);
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_body && val.Alive && val.IsLocalPlayer && Mathf.Abs(((Component)val).transform.position.y - ((Component)this).transform.position.y) <= 8f)
			{
				return CodexFendaHostil.Plugin.AllowsDamage(((Component)val).transform.position);
			}
			return false;
		}

		private void RockHit(Collider col, Vector3 point)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			if (!((Object)(object)_body == (Object)null) && _body.Alive && !_motor.Dead && IsVictim(col))
			{
				Character ownerChar = ((Component)col).GetComponentInParent<Hitbox>().OwnerChar;
				DamageList val = new DamageList((Types)0, 28f);
				Vector3 val2 = ownerChar.CenterPosition - ((Component)this).transform.position;
				ownerChar.ReceiveHit((Object)null, val, ((Vector3)(ref val2)).normalized, point, 45f, 1f, _body, 32f, true);
				Plugin.Instance.Message("ROCHA acertou " + ownerChar.Name + ":28fisico/32impacto,uma vez.");
			}
		}

		private void Heal(float amount)
		{
			if (!((Object)(object)_body == (Object)null) && _body.Alive && !_motor.Dead && !(_body.Stats.CurrentHealth >= 600f))
			{
				_body.Stats.SetHealth(ForestCombat.HealedHealth(_body.Stats.CurrentHealth, amount));
				_slam.Regenerate();
				Plugin.Instance.Message("REGENERACAO:2vida,fora do combate e parado;vida=" + _body.Stats.CurrentHealth);
			}
		}

		private void Dead()
		{
			if ((Object)(object)_motor != (Object)null)
			{
				_motor.Kill();
			}
			if ((Object)(object)_slam != (Object)null)
			{
				_slam.Hide();
			}
			foreach (ForestRock rock in _rocks)
			{
				if ((Object)(object)rock != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)rock).gameObject);
				}
			}
			_rocks.Clear();
		}

		private void LateUpdate()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body == (Object)null || (Object)(object)_motor == (Object)null)
			{
				return;
			}
			((Component)_body).transform.SetPositionAndRotation(((Component)this).transform.position, ((Component)this).transform.rotation);
			Rigidbody[] rigidbodies = _rigidbodies;
			foreach (Rigidbody val in rigidbodies)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.isKinematic = true;
					val.useGravity = false;
				}
			}
			Collider[] nativeColliders = _nativeColliders;
			foreach (Collider val2 in nativeColliders)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.enabled = false;
				}
			}
			if ((Object)(object)_receiver != (Object)null)
			{
				((Component)_receiver).gameObject.SetActive(!_motor.Dead);
			}
			if ((Object)(object)_locking != (Object)null)
			{
				((Collider)_locking).enabled = !_motor.Dead;
			}
		}

		private void OnDestroy()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)_body != (Object)null)
			{
				Character body = _body;
				body.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)body.OnDeath, (Delegate?)new UnityAction(Dead));
			}
			Dead();
		}
	}
	public sealed class ForestMotor : MonoBehaviour
	{
		public const float DetectRange = 30f;

		public const float Leash = 10f;

		public const float Reach = 3.1f;

		public const float ShotRange = 22f;

		public const float Speed = 1.2f;

		public Func<Vector3?> Target;

		public Func<bool> Paused;

		public Action Slam;

		public Action<int> Strike;

		public Action<Vector3> Shoot;

		public Action<float> Warning;

		public Action<float> Heal;

		public Action<bool> RageChanged;

		public Action<string> Trace;

		private CharacterController _controller;

		private Animation _animation;

		private int _environment;

		private string _clip;

		private float _vertical;

		private float _until;

		private float _strikeAt;

		private float _nextShot;

		private float _lastActive;

		private float _lastHurt = -10f;

		private float _nextHeal;

		private float _walkSpeed = 1f;

		private bool _struck;

		private bool _throw;

		private int _closeCycles;

		private int _comboStep;

		private int _burstRemaining;

		private Vector3 _aim;

		private Vector3 _velocity;

		public string Phase { get; private set; }

		public bool Dead { get; private set; }

		public Vector3 Home { get; private set; }

		public float DistanceWalked { get; private set; }

		public int Slams { get; private set; }

		public int Shots { get; private set; }

		public int Strikes { get; private set; }

		public int Combos { get; private set; }

		public bool Enraged { get; private set; }

		public int Staggers { get; private set; }

		public void Initialize(Animation animation, CharacterController controller, int environment)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_animation = animation;
			_controller = controller;
			_environment = environment;
			Home = ((Component)this).transform.position;
			string[] array = new string[5] { "Idle", "Walk", "Attack", "Prepare", "Death" };
			foreach (string text in array)
			{
				if ((TrackedReference)(object)animation[text] == (TrackedReference)null)
				{
					throw new InvalidOperationException("Missing external clip:" + text);
				}
			}
			_lastActive = Time.time;
			_nextShot = Time.time + 1f;
			Phase = "Idle";
			Play("Idle");
		}

		public void SetHealth(float health)
		{
			bool flag = !Dead && health > 0f && health <= 240f;
			if (flag != Enraged)
			{
				Enraged = flag;
				RageChanged?.Invoke(flag);
				Trace?.Invoke(flag ? "FURIA:vida<=40%,passo acelerado e duas pedradas." : "Furia encerrada.");
			}
		}

		public void Hurt(float damage = 25f)
		{
			if (!Dead)
			{
				_lastActive = Time.time;
				if (!(damage < 8f) && !(Time.time - _lastHurt < 5f))
				{
					Staggers++;
					_lastHurt = Time.time;
					_burstRemaining = 0;
					Phase = "Hurt";
					_until = Time.time + 0.28f;
					Warning?.Invoke(0f);
					Play("Idle", restart: true);
					Trace?.Invoke("Cambaleio:golpe>=8,intervalo minimo5s.");
				}
			}
		}

		public void Kill()
		{
			if (!Dead)
			{
				Dead = true;
				_burstRemaining = 0;
				SetHealth(0f);
				Phase = "Dead";
				Warning?.Invoke(0f);
				Play("Death", restart: true);
				Trace?.Invoke("Morte com animacao externa CDmir.");
			}
		}

		private void Update()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_controller == (Object)null) && ((Collider)_controller).enabled && (Paused == null || !Paused()))
			{
				float num = Mathf.Min(Time.deltaTime, 0.25f);
				Vector3 val = (Dead ? Vector3.zero : Think());
				bool flag = Phase == "Chase" || Phase == "Return";
				_velocity = (flag ? Vector3.MoveTowards(_velocity, val, 6f * num) : Vector3.zero);
				Vector3 position = ((Component)this).transform.position;
				int num2 = Mathf.Max(1, Mathf.CeilToInt(num / 0.025f));
				float num3 = num / (float)num2;
				for (int i = 0; i < num2; i++)
				{
					_vertical = (_controller.isGrounded ? (-2f) : Mathf.Max(_vertical - 22f * num3, -20f));
					_controller.Move((_velocity + Vector3.up * _vertical) * num3);
				}
				Vector3 val2 = ((Component)this).transform.position - position;
				val2.y = 0f;
				DistanceWalked += ((Vector3)(ref val2)).magnitude;
				if (((Vector3)(ref val2)).sqrMagnitude > 1E-05f)
				{
					_lastActive = Time.time;
				}
				if (_clip == "Walk")
				{
					float num4 = Mathf.Clamp(((Vector3)(ref val2)).magnitude / Mathf.Max(num, 0.0001f) / 1.2f, 0.4f, 1.4f);
					_walkSpeed = Mathf.MoveTowards(_walkSpeed, num4, 3f * num);
					_animation["Walk"].speed = _walkSpeed;
				}
			}
		}

		private Vector3 Think()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: 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_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0618: Unknown result type (might be due to invalid IL or missing references)
			//IL_0671: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: 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_0681: 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_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0718: 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_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_071d: Unknown result type (might be due to invalid IL or missing references)
			//IL_071e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0725: Unknown result type (might be due to invalid IL or missing references)
			//IL_072a: Unknown result type (might be due to invalid IL or missing references)
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_080a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0817: Unknown result type (might be due to invalid IL or missing references)
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0830: Unknown result type (might be due to invalid IL or missing references)
			//IL_0831: Unknown result type (might be due to invalid IL or missing references)
			//IL_0836: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_085b: 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_07d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: 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_0a00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a05: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a20: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a25: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a2a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0928: Unknown result type (might be due to invalid IL or missing references)
			//IL_092d: Unknown result type (might be due to invalid IL or missing references)
			//IL_092f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0934: Unknown result type (might be due to invalid IL or missing references)
			//IL_0945: Unknown result type (might be due to invalid IL or missing references)
			//IL_094a: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0951: Unknown result type (might be due to invalid IL or missing references)
			//IL_0959: Unknown result type (might be due to invalid IL or missing references)
			//IL_095e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0968: Unknown result type (might be due to invalid IL or missing references)
			//IL_096d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0977: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0803: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a59: Unknown result type (might be due to invalid IL or missing references)
			//IL_099a: Unknown result type (might be due to invalid IL or missing references)
			//IL_099f: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_098e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0990: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ec: 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_09f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0899: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a80: Unknown result type (might be due to invalid IL or missing references)
			//IL_089f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a96: Unknown result type (might be due to invalid IL or missing references)
			if (Phase == "Hurt" && Time.time < _until)
			{
				return Vector3.zero;
			}
			if (Phase == "BurstWindup")
			{
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				Vector3? val = Target?.Invoke();
				if (val.HasValue)
				{
					Vector3 val2 = val.Value - ((Component)this).transform.position;
					if (!(((Vector3)(ref val2)).magnitude > 22f) && !Physics.Linecast(((Component)this).transform.position + Vector3.up * 2f, val.Value + Vector3.up, _environment, (QueryTriggerInteraction)1))
					{
						_aim = val.Value + Vector3.up;
						Phase = "Throw";
						Play("Attack", restart: true);
						_strikeAt = Time.time + _animation["Attack"].length * 0.43f;
						_until = Time.time + _animation["Attack"].length;
						_struck = false;
						Trace?.Invoke("Furia:segunda pedrada preparada,nao teleguiada.");
						return Vector3.zero;
					}
				}
				Recover();
				return Vector3.zero;
			}
			if (Phase == "ComboWindup")
			{
				Vector3? val3 = Target?.Invoke();
				if (val3.HasValue)
				{
					Vector3 direction = val3.Value - ((Component)this).transform.position;
					direction.y = 0f;
					Turn(direction);
				}
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				Phase = "ComboStrike";
				Play("Attack", restart: true);
				_animation["Attack"].speed = 1.35f;
				float num = _animation["Attack"].length / 1.35f;
				_strikeAt = Time.time + num * 0.43f;
				_until = Time.time + num;
				_struck = false;
				return Vector3.zero;
			}
			if (Phase == "ComboStrike")
			{
				if (!_struck && Time.time >= _strikeAt)
				{
					_struck = true;
					Strikes++;
					_lastActive = Time.time;
					Strike?.Invoke(_comboStep);
					if (Dead || Phase == "Hurt")
					{
						return Vector3.zero;
					}
				}
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				Phase = "ComboGap";
				_until = Time.time + 0.3f;
				Play("Prepare", restart: true);
				return Vector3.zero;
			}
			if (Phase == "ComboGap")
			{
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				Vector3? val4 = Target?.Invoke();
				if (!val4.HasValue || !ForestCombat.CanSlam(((Component)this).transform.position, val4.Value, val4.Value + Vector3.up, _environment))
				{
					Recover();
					return Vector3.zero;
				}
				Turn(val4.Value - ((Component)this).transform.position);
				if (_comboStep == 1)
				{
					_comboStep = 2;
					Phase = "ComboWindup";
					_until = Time.time + 0.2f;
					Play("Prepare", restart: true);
				}
				else
				{
					Begin(ranged: false, val4.Value);
					Trace?.Invoke("Combo:preparando abalo final5m.");
				}
				return Vector3.zero;
			}
			if (Phase == "Warning")
			{
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				Phase = (_throw ? "Throw" : "Slam");
				Play("Attack", restart: true);
				_strikeAt = Time.time + _animation["Attack"].length * 0.43f;
				_until = Time.time + _animation["Attack"].length;
				_struck = false;
				return Vector3.zero;
			}
			if (Phase == "Throw" || Phase == "Slam")
			{
				if (!_struck && Time.time >= _strikeAt)
				{
					_struck = true;
					Warning?.Invoke(0f);
					if (_throw)
					{
						Shots++;
						Shoot?.Invoke(_aim);
					}
					else
					{
						Slams++;
						Slam?.Invoke();
					}
					if (Dead || Phase == "Hurt")
					{
						return Vector3.zero;
					}
				}
				if (Time.time < _until)
				{
					return Vector3.zero;
				}
				if (_throw && _burstRemaining > 0)
				{
					_burstRemaining--;
					Phase = "BurstWindup";
					_until = Time.time + 0.45f;
					Play("Prepare", restart: true);
					return Vector3.zero;
				}
				Recover();
				return Vector3.zero;
			}
			if (Phase == "Recovery" && Time.time < _until)
			{
				return Vector3.zero;
			}
			Vector3? val5 = Target?.Invoke();
			Vector3 val6 = ((Component)this).transform.position - Home;
			val6.y = 0f;
			bool flag = !val5.HasValue || ((Vector3)(ref val6)).magnitude > 10f;
			if (val5.HasValue)
			{
				Vector3 val7 = val5.Value - Home;
				val7.y = 0f;
				if (((Vector3)(ref val7)).magnitude > 32f || Mathf.Abs(val5.Value.y - ((Component)this).transform.position.y) > 3f)
				{
					flag = true;
				}
			}
			Vector3 val8 = (flag ? Home : val5.Value);
			Vector3 val9 = val8 - ((Component)this).transform.position;
			val9.y = 0f;
			float magnitude = ((Vector3)(ref val9)).magnitude;
			if (flag && magnitude < 0.2f)
			{
				Phase = "Idle";
				Play("Idle");
				if (!val5.HasValue && Time.time - _lastActive >= 5f && Time.time >= _nextHeal)
				{
					_nextHeal = Time.time + 1f;
					Heal?.Invoke(2f);
				}
				return Vector3.zero;
			}
			if (!flag && magnitude <= 3.1f && Vector3.Angle(((Component)this).transform.forward, val9) >= 25f)
			{
				Turn(val9);
				Phase = "Turn";
				Play("Idle");
				return Vector3.zero;
			}
			Turn(val9);
			bool flag2 = !Physics.Linecast(((Component)this).transform.position + Vector3.up * 2f, val8 + Vector3.up, _environment, (QueryTriggerInteraction)1);
			if (!flag && flag2 && Vector3.Angle(((Component)this).transform.forward, val9) < 25f)
			{
				if (magnitude <= 3.1f)
				{
					if (++_closeCycles % 2 == 0)
					{
						BeginCombo();
					}
					else
					{
						Begin(ranged: false, val8);
					}
					return Vector3.zero;
				}
				if (magnitude >= 6f && magnitude <= 22f && Time.time >= _nextShot)
				{
					Begin(ranged: true, val8);
					return Vector3.zero;
				}
			}
			Vector3 val10 = ((Vector3)(ref val9)).normalized;
			RaycastHit val11 = default(RaycastHit);
			if (Physics.SphereCast(((Component)this).transform.position + Vector3.up * 1.4f, 0.8f, val10, ref val11, 1.8f, _environment, (QueryTriggerInteraction)1))
			{
				Vector3 val12 = Quaternion.Euler(0f, -65f, 0f) * val10;
				Vector3 val13 = Quaternion.Euler(0f, 65f, 0f) * val10;
				if (!Physics.SphereCast(((Component)this).transform.position + Vector3.up * 1.4f, 0.8f, val12, ref val11, 1.8f, _environment, (QueryTriggerInteraction)1))
				{
					val10 = val12;
				}
				else
				{
					if (Physics.SphereCast(((Component)this).transform.position + Vector3.up * 1.4f, 0.8f, val13, ref val11, 1.8f, _environment, (QueryTriggerInteraction)1))
					{
						Phase = "Blocked";
						Play("Idle");
						return Vector3.zero;
					}
					val10 = val13;
				}
				Turn(val10);
			}
			if (!Physics.Raycast(((Component)this).transform.position + val10 * 1.5f + Vector3.up * 0.6f, Vector3.down, 1.4f, _environment, (QueryTriggerInteraction)1))
			{
				Phase = "Blocked";
				Play("Idle");
				return Vector3.zero;
			}
			Phase = (flag ? "Return" : "Chase");
			Play("Walk");
			return val10 * (Enraged ? 1.6f : 1.2f);
		}

		private void Begin(bool ranged, Vector3 goal)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_throw = ranged;
			_aim = goal + Vector3.up;
			_lastActive = Time.time;
			_burstRemaining = ((ranged && Enraged) ? 1 : 0);
			Phase = "Warning";
			_until = Time.time + (ranged ? 1f : 0.7f);
			_nextShot = Time.time + 6f;
			Play("Prepare", restart: true);
			if (!ranged)
			{
				Warning?.Invoke(0.7f + _animation["Attack"].length * 0.43f);
			}
			Trace?.Invoke(ranged ? "Preparando pedrada externa." : "Preparando pancada de area5m.");
		}

		private void BeginCombo()
		{
			Combos++;
			_comboStep = 1;
			_lastActive = Time.time;
			_nextShot = Time.time + 6f;
			Warning?.Invoke(0f);
			Phase = "ComboWindup";
			_until = Time.time + 0.65f;
			Play("Prepare", restart: true);
			Trace?.Invoke("Combo externo:dois golpes frontais22/26 e abalo36;preparo visivel.");
		}

		private void Recover()
		{
			_lastActive = Time.time;
			Phase = "Recovery";
			_until = Time.time + 1.6f;
			Warning?.Invoke(0f);
			Play("Idle");
		}

		private void Turn(Vector3 direction)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (((Vector3)(ref direction)).sqrMagnitude > 0.001f)
			{
				((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(direction), 140f * Time.deltaTime);
			}
		}

		private void Play(string clip, bool restart = false)
		{
			if (!(_clip == clip) || restart)
			{
				_clip = clip;
				_animation[clip].speed = ((clip == "Walk") ? _walkSpeed : 1f);
				if (clip == "Walk")
				{
					_animation[clip].wrapMode = (WrapMode)2;
				}
				if (restart)
				{
					_animation[clip].time = 0f;
				}
				_animation.CrossFade(clip, 0.12f);
			}
		}
	}
	public sealed class ForestRock : MonoBehaviour
	{
		public const float Speed = 8f;

		public const float Gravity = 4f;

		public const float Radius = 0.28f;

		public const float Range = 22f;

		public Func<Collider, bool> Victim;

		public Action<Collider, Vector3> Hit;

		public Func<bool> Paused;

		public Func<bool> Visible;

		private int _environment;

		private int _targets;

		private float _age;

		private Mesh _mesh;

		private Material _material;

		private MeshRenderer _renderer;

		public float Travelled { get; private set; }

		public bool Finished { get; private set; }

		public Vector3 Velocity { get; private set; }

		public void Initialize(Vector3 aim, int environment, int targets)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			Vector3 val = aim - ((Component)this).transform.position;
			Vector3 val2 = val;
			val2.y = 0f;
			if (((Vector3)(ref val2)).magnitude < 0.1f)
			{
				throw new ArgumentException("Rock aim has no horizontal direction");
			}
			float num = ((Vector3)(ref val2)).magnitude / 8f;
			Velocity = ((Vector3)(ref val2)).normalized * 8f + Vector3.up * (val.y / num + 2f * num);
			_environment = environment;
			_targets = targets;
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val3).name = "Rocha_Visual";
			val3.transform.SetParent(((Component)this).transform, false);
			Collider component = val3.GetComponent<Collider>();
			component.enabled = false;
			Object.Destroy((Object)(object)

BepInEx/plugins/Codex_Flor_Predadora/CodexFlorPredadora.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CodexCombat;
using CodexSwamp;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexSwamp
{
	internal static class PoisonOnHit
	{
		internal static void Apply(Character source, Character target, StatusEffect poison, bool blocked)
		{
			if (!blocked && !((Object)(object)target == (Object)null) && target.Alive && !((Object)(object)poison == (Object)null) && !((Object)(object)target.StatusEffectMngr == (Object)null))
			{
				target.StatusEffectMngr.AddStatusEffect(poison, source);
			}
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexFlorPredadora
{
	internal enum PlantPhase
	{
		Idle,
		WhipWarning,
		Whip,
		Recover,
		SeedWarning,
		Volley,
		Cooldown,
		Dead
	}
	internal sealed class PlantBrain
	{
		internal const float Health = 260f;

		internal const float DetectRange = 30f;

		internal const float MeleeRange = 4.4f;

		internal const float SeedSpeed = 18f;

		internal const float SeedRange = 30f;

		internal const float ContactDamage = 24f;

		internal const float ContactImpact = 20f;

		internal const float SeedDamage = 16f;

		internal const float SeedImpact = 8f;

		private readonly float meleeRange;

		internal PlantPhase Phase { get; private set; }

		internal float Started { get; private set; }

		internal float Deadline { get; private set; }

		internal int Combo { get; private set; }

		internal PlantBrain()
			: this(1f)
		{
		}

		internal PlantBrain(float scale)
		{
			if (float.IsNaN(scale) || float.IsInfinity(scale) || scale <= 0f)
			{
				throw new ArgumentOutOfRangeException("scale");
			}
			meleeRange = 4.4f * scale;
		}

		private void Begin(PlantPhase phase, float time, float duration)
		{
			Phase = phase;
			Started = time;
			Deadline = time + duration;
		}

		internal PlantPhase Step(float time, bool alive, bool visible, float distance)
		{
			if (!alive)
			{
				Begin(PlantPhase.Dead, time, 0f);
				return Phase;
			}
			if (Phase == PlantPhase.Dead)
			{
				return Phase;
			}
			if ((Phase == PlantPhase.WhipWarning || Phase == PlantPhase.SeedWarning) && !visible)
			{
				Begin(PlantPhase.Cooldown, time, 0.8f);
				return Phase;
			}
			switch (Phase)
			{
			case PlantPhase.Idle:
				if (visible && distance <= 30f)
				{
					Combo = 0;
					Begin((distance <= meleeRange) ? PlantPhase.WhipWarning : PlantPhase.SeedWarning, time, (distance <= meleeRange) ? 0.65f : 0.95f);
				}
				break;
			case PlantPhase.WhipWarning:
				if (time >= Deadline)
				{
					Begin(PlantPhase.Whip, time, 0.28f);
				}
				break;
			case PlantPhase.Whip:
				if (time >= Deadline)
				{
					Begin(PlantPhase.Recover, time, 0.4f);
				}
				break;
			case PlantPhase.Recover:
				if (time >= Deadline)
				{
					if (Combo == 0 && visible && distance <= meleeRange + 1f)
					{
						Combo = 1;
						Begin(PlantPhase.WhipWarning, time, 0.4f);
					}
					else
					{
						Begin(PlantPhase.Cooldown, time, 2.2f);
					}
				}
				break;
			case PlantPhase.SeedWarning:
				if (time >= Deadline)
				{
					Begin(PlantPhase.Volley, time, 0.3f);
				}
				break;
			case PlantPhase.Volley:
				if (time >= Deadline)
				{
					Begin(PlantPhase.Cooldown, time, 2.8f);
				}
				break;
			case PlantPhase.Cooldown:
				if (time >= Deadline)
				{
					Begin(PlantPhase.Idle, time, 0f);
				}
				break;
			}
			return Phase;
		}

		internal static float SegmentFraction(float px, float py, float pz, float ax, float ay, float az, float bx, float by, float bz)
		{
			float num = bx - ax;
			float num2 = by - ay;
			float num3 = bz - az;
			float num4 = num * num + num2 * num2 + num3 * num3;
			if (!(num4 < 1E-06f))
			{
				return Math.Max(0f, Math.Min(1f, ((px - ax) * num + (py - ay) * num2 + (pz - az) * num3) / num4));
			}
			return 0f;
		}

		internal static bool InContactCone(float distance, float dot)
		{
			if (distance <= 4.4f)
			{
				return dot >= 0.866f;
			}
			return false;
		}

		internal static bool InScaledContactCone(float distance, float dot, float scale)
		{
			return InContactCone(distance / scale, dot);
		}
	}
	internal sealed class HiddenPlantReceiver : MonoBehaviour
	{
		private readonly List<Renderer> renderers = new List<Renderer>();

		private float next;

		private void LateUpdate()
		{
			if (Time.unscaledTime >= next)
			{
				((Component)this).GetComponentsInChildren<Renderer>(true, renderers);
				next = Time.unscaledTime + 0.15f;
			}
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = false;
				}
			}
		}
	}
	internal sealed class PlantEnemy : MonoBehaviour
	{
		private sealed class Shot
		{
			internal Vector3 Position;

			internal Vector3 Direction;

			internal float Travel;

			internal GameObject Visual;
		}

		private Character body;

		private PlantVisual visual;

		private Vector3 anchor;

		private PlantBrain brain = new PlantBrain();

		private PlantPhase prior;

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

		private List<Character> targets = new List<Character>();

		private readonly List<Shot> shots = new List<Shot>();

		private readonly List<Collider> receivers = new List<Collider>();

		private StatusEffect poison;

		private float clock;

		private float nextTargets;

		private float nextVisibility;

		private bool ready;

		private bool dead;

		internal void Initialize(Character native, PlantVisual model, Vector3 floor)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Expected O, but got Unknown
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Expected O, but got Unknown
			body = native;
			visual = model;
			anchor = floor + Vector3.up * 0.08f;
			brain = new PlantBrain(visual.Scale);
			CharacterAI component = ((Component)body).GetComponent<CharacterAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			NavMeshAgent component2 = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			CharacterControl component3 = ((Component)body).GetComponent<CharacterControl>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			if ((Object)(object)body.CharacterController != (Object)null)
			{
				((Collider)body.CharacterController).enabled = false;
			}
			Collider[] componentsInChildren = ((Component)body).GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Rigidbody[] componentsInChildren2 = ((Component)body).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren2)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			int num = LayerMask.NameToLayer("Hitbox");
			if (num < 0)
			{
				throw new InvalidOperationException("Camada Hitbox ausente");
			}
			List<Hitbox> list = new List<Hitbox>();
			for (int j = 0; j < 2; j++)
			{
				GameObject val = new GameObject("Flor_Receptor_" + j);
				val.transform.SetParent(((Component)body).transform, false);
				val.layer = num;
				if (j == 0)
				{
					CapsuleCollider val2 = val.AddComponent<CapsuleCollider>();
					val2.center = Vector3.up * (0.85f * visual.Scale);
					val2.radius = 0.58f * visual.Scale;
					val2.height = 1.7f * visual.Scale;
					((Collider)val2).isTrigger = true;
					receivers.Add((Collider)(object)val2);
				}
				else
				{
					SphereCollider val3 = val.AddComponent<SphereCollider>();
					val3.center = Vector3.up * (2.32f * visual.Scale);
					val3.radius = 1.05f * visual.Scale;
					((Collider)val3).isTrigger = true;
					receivers.Add((Collider)(object)val3);
				}
				Hitbox val4 = val.AddComponent<Hitbox>();
				val4.OwnerChar = body;
				val4.Melee = true;
				val4.Ranged = true;
				list.Add(val4);
			}
			FieldInfo? field = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("Character.m_hitboxes");
			}
			field.SetValue(body, list.ToArray());
			int num2 = LayerMask.NameToLayer("LockingPoints");
			if (num2 < 0 || (Global.LockingPointsMask & (1 << num2)) == 0)
			{
				throw new InvalidOperationException("Mira nativa LockingPoints ausente");
			}
			GameObject val5 = new GameObject("Flor_Mira_TAB");
			val5.transform.SetParent(((Component)body).transform, false);
			val5.transform.localPosition = Vector3.up * (2.32f * visual.Scale);
			val5.layer = num2;
			SphereCollider val6 = val5.AddComponent<SphereCollider>();
			val6.radius = 0.18f * visual.Scale;
			((Collider)val6).isTrigger = true;
			receivers.Add((Collider)(object)val6);
			LockingPoint obj2 = val5.AddComponent<LockingPoint>();
			obj2.OwnerChar = body;
			obj2.HideFlare = false;
			poison = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Poisoned");
			if ((Object)(object)poison == (Object)null)
			{
				Plugin.Instance.Message("AVISO:Poisoned ausente;ataques causam dano mas sem veneno.");
			}
			Character obj3 = body;
			obj3.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)obj3.OnDeath, (Delegate?)new UnityAction(Die));
			ready = true;
		}

		private void Update()
		{
			//IL_004c: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: 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_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: 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_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: 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_034d: Unknown result type (might be due to invalid IL or missing references)
			if (!ready || (Object)(object)body == (Object)null || (Object)(object)visual == (Object)null)
			{
				return;
			}
			if (!body.Alive)
			{
				Die();
			}
			if (Time.unscaledTime >= nextVisibility)
			{
				visual.Visible((Object)(object)Plugin.Nearest(anchor, 150f) != (Object)null);
				nextVisibility = Time.unscaledTime + 0.25f;
			}
			if ((Object)(object)NetworkLevelLoader.Instance == (Object)null || !NetworkLevelLoader.Instance.IsOverallLoadingDone || NetworkLevelLoader.Instance.IsGameplayPaused)
			{
				return;
			}
			clock += Time.deltaTime;
			if (dead)
			{
				visual.Pose(PlantPhase.Dead, 0f, 0, clock);
				return;
			}
			if (clock >= nextTargets)
			{
				targets.Clear();
				CharacterManager.Instance.FindCharactersInRange(anchor, 33f, ref targets);
				nextTargets = clock + 0.2f;
			}
			Character val = null;
			float num = float.MaxValue;
			Vector3 val2;
			foreach (Character target in targets)
			{
				if (Valid(target))
				{
					val2 = target.CenterPosition - anchor;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					if (magnitude < num)
					{
						val = target;
						num = magnitude;
					}
				}
			}
			int num3;
			if ((Object)(object)val != (Object)null)
			{
				float num2 = Clip(visual.Muzzle, val.CenterPosition - visual.Muzzle, swept: false);
				val2 = val.CenterPosition - visual.Muzzle;
				num3 = ((num2 >= ((Vector3)(ref val2)).magnitude - 0.05f) ? 1 : 0);
			}
			else
			{
				num3 = 0;
			}
			bool flag = (byte)num3 != 0;
			if ((Object)(object)val != (Object)null && brain.Phase != PlantPhase.Whip && brain.Phase != PlantPhase.Recover && brain.Phase != PlantPhase.Volley)
			{
				visual.Face(val.CenterPosition - anchor, Time.deltaTime);
			}
			if ((Object)(object)val != (Object)null)
			{
				Vector3 val3 = val.CenterPosition - visual.Muzzle;
				val3.y = 0f;
				flag = flag && (((Vector3)(ref val3)).sqrMagnitude < 0.01f || Vector3.Angle(visual.Head.forward, val3) < 35f);
			}
			PlantPhase plantPhase = brain.Step(clock, alive: true, flag, num);
			if (plantPhase != prior)
			{
				if (plantPhase == PlantPhase.Whip)
				{
					hit.Clear();
				}
				if (plantPhase == PlantPhase.Volley && (Object)(object)val != (Object)null)
				{
					val2 = val.CenterPosition - visual.Muzzle;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					for (int i = -1; i <= 1; i++)
					{
						Vector3 direction = Quaternion.Euler(0f, (float)(i * 8), 0f) * normalized;
						shots.Add(new Shot
						{
							Position = visual.Muzzle,
							Direction = direction,
							Visual = visual.Seed(visual.Muzzle)
						});
					}
				}
				prior = plantPhase;
			}
			float progress = Mathf.Clamp01((clock - brain.Started) / Mathf.Max(0.001f, brain.Deadline - brain.Started));
			visual.Pose(plantPhase, progress, brain.Combo, clock);
			if (plantPhase == PlantPhase.Whip)
			{
				Contact();
			}
			Projectiles();
		}

		private static bool Valid(Character target)
		{
			if ((Object)(object)target != (Object)null && target.IsLocalPlayer)
			{
				return target.Alive;
			}
			return false;
		}

		private void Contact()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0106: 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)
			foreach (Character target in targets)
			{
				if (!Valid(target) || hit.Contains(target))
				{
					continue;
				}
				Vector3 val = target.CenterPosition - ((Component)visual).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).magnitude > visual.TendrilReach(brain.Combo) + 0.4f * visual.Scale || !PlantBrain.InScaledContactCone(((Vector3)(ref val)).magnitude, Vector3.Dot(visual.TendrilDirection(brain.Combo), ((Vector3)(ref val)).normalized), visual.Scale))
				{
					continue;
				}
				Vector3 val2 = anchor + Vector3.up * (0.9f * visual.Scale);
				Vector3 segment = target.CenterPosition - val2;
				if (!(Clip(val2, segment, swept: false) < ((Vector3)(ref segment)).magnitude - 0.05f))
				{
					hit.Add(target);
					bool flag = PhysicalContactHit.Apply((MonoBehaviour)(object)this, body, target, 24f, ((Vector3)(ref val)).normalized, 20f, blockable: true);
					PoisonOnHit.Apply(body, target, poison, flag);
					if (Plugin.Instance.Detailed.Value)
					{
						Plugin.Instance.Message("Tentaculo " + brain.Combo + (flag ? " BLOQUEADO" : " ACERTO") + " em " + target.Name);
					}
				}
			}
		}

		private void Projectiles()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: 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_029c: Unknown result type (might be due to invalid IL or missing references)
			for (int num = shots.Count - 1; num >= 0; num--)
			{
				Shot shot = shots[num];
				float num2 = Mathf.Min(18f * Time.deltaTime, 30f - shot.Travel);
				Vector3 segment = shot.Direction * num2;
				float num3 = Clip(shot.Position, segment, swept: true);
				Vector3 val = shot.Position + shot.Direction * num3;
				Character val2 = null;
				float num4 = 2f;
				foreach (Character target in targets)
				{
					if (Valid(target))
					{
						Vector3 centerPosition = target.CenterPosition;
						float num5 = PlantBrain.SegmentFraction(centerPosition.x, centerPosition.y, centerPosition.z, shot.Position.x, shot.Position.y, shot.Position.z, val.x, val.y, val.z);
						Vector3 segment2 = centerPosition - shot.Position;
						Vector3 val3 = centerPosition - Vector3.Lerp(shot.Position, val, num5);
						if (((Vector3)(ref val3)).sqrMagnitude < 0.3025f && num5 < num4 && Clip(shot.Position, segment2, swept: false) >= ((Vector3)(ref segment2)).magnitude - 0.02f)
						{
							num4 = num5;
							val2 = target;
						}
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.ReceiveHit((Object)null, new DamageList((Types)2, 16f), shot.Direction, val2.CenterPosition, 45f, 1f, body, 8f, true);
					PoisonOnHit.Apply(body, val2, poison, blocked: false);
					if (Plugin.Instance.Detailed.Value)
					{
						Plugin.Instance.Message("Semente ACERTO em " + val2.Name + ";Decay16/Poisoned direto100%;nao bloqueavel/imunidade nativa respeitada.");
					}
				}
				shot.Travel += num3;
				shot.Position = val;
				if ((Object)(object)val2 != (Object)null || num3 < num2 - 0.001f || shot.Travel >= 29.999f)
				{
					if ((Object)(object)shot.Visual != (Object)null)
					{
						Object.Destroy((Object)(object)shot.Visual);
					}
					shots.RemoveAt(num);
				}
				else if ((Object)(object)shot.Visual != (Object)null)
				{
					shot.Visual.transform.position = val;
					shot.Visual.transform.rotation = Quaternion.LookRotation(shot.Direction);
				}
			}
		}

		private float Clip(Vector3 start, Vector3 segment, bool swept)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Vector3)(ref segment)).magnitude;
			if (num < 1E-05f)
			{
				return num;
			}
			RaycastHit[] array = (swept ? Physics.SphereCastAll(start, 0.1f, segment / num, num, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1) : Physics.RaycastAll(start, segment / num, num, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1));
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)this).transform) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)visual).transform) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>() != (Object)null))
				{
					num = Mathf.Min(num, ((RaycastHit)(ref val)).distance);
				}
			}
			return num;
		}

		private void Die()
		{
			if (dead)
			{
				return;
			}
			dead = true;
			brain.Step(clock, alive: false, visible: false, 0f);
			visual.Die();
			foreach (Collider receiver in receivers)
			{
				if ((Object)(object)receiver != (Object)null)
				{
					receiver.enabled = false;
				}
			}
			foreach (Shot shot in shots)
			{
				if ((Object)(object)shot.Visual != (Object)null)
				{
					Object.Destroy((Object)(object)shot.Visual);
				}
			}
			shots.Clear();
			Plugin.Instance.Message("MORTA por dano nativo;ataques/projeteis cancelados,sem drop;F10 perto recria somente a flor.");
		}

		private void LateUpdate()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (ready && (Object)(object)body != (Object)null)
			{
				((Component)body).transform.position = anchor;
			}
		}

		private void OnDestroy()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)body != (Object)null)
			{
				Character obj = body;
				obj.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)obj.OnDeath, (Delegate?)new UnityAction(Die));
			}
			foreach (Shot shot in shots)
			{
				if ((Object)(object)shot.Visual != (Object)null)
				{
					Object.Destroy((Object)(object)shot.Visual);
				}
			}
			shots.Clear();
			if ((Object)(object)visual != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)visual).gameObject);
			}
		}
	}
	internal static class PlantGeometry
	{
		internal const int Sides = 12;

		internal static Vector3[] Tube(Vector3[] centers, float[] radius)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[centers.Length * 12 + 2];
			for (int i = 0; i < centers.Length; i++)
			{
				Vector3 val = centers[Mathf.Min(i + 1, centers.Length - 1)] - centers[Mathf.Max(0, i - 1)];
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val2 = ((Mathf.Abs(normalized.x) < 0.85f) ? Vector3.right : Vector3.forward);
				val = val2 - normalized * Vector3.Dot(val2, normalized);
				Vector3 normalized2 = ((Vector3)(ref val)).normalized;
				Vector3 val3 = Vector3.Cross(normalized2, normalized);
				for (int j = 0; j < 12; j++)
				{
					float num = (float)j * (float)Math.PI * 2f / 12f;
					array[i * 12 + j] = centers[i] + radius[i] * (Mathf.Cos(num) * normalized2 + Mathf.Sin(num) * val3);
				}
			}
			array[^2] = centers[0];
			array[^1] = centers[^1];
			return array;
		}

		internal static int[] TubeTriangles(int rings)
		{
			int num = 0;
			int[] array = new int[(rings - 1) * 12 * 6 + 72];
			for (int i = 0; i < rings - 1; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					int num2 = i * 12 + j;
					int num3 = i * 12 + (j + 1) % 12;
					int num4 = num3 + 12;
					int num5 = num2 + 12;
					array[num++] = num2;
					array[num++] = num5;
					array[num++] = num3;
					array[num++] = num3;
					array[num++] = num5;
					array[num++] = num4;
				}
			}
			for (int k = 0; k < 12; k++)
			{
				array[num++] = rings * 12;
				array[num++] = k;
				array[num++] = (k + 1) % 12;
				array[num++] = rings * 12 + 1;
				array[num++] = (rings - 1) * 12 + (k + 1) % 12;
				array[num++] = (rings - 1) * 12 + k;
			}
			return array;
		}

		internal static Vector3[] PetalVertices()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[154];
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 11; j++)
				{
					for (int k = 0; k < 7; k++)
					{
						float num = (float)j / 10f;
						float num2 = (float)k / 6f * 2f - 1f;
						float num3 = 0.025f + 0.51f * Mathf.Pow(Mathf.Clamp01(Mathf.Sin(num * (float)Math.PI)), 0.7f);
						array[i * 11 * 7 + j * 7 + k] = new Vector3(num2 * num3, num * 1.65f, 0.24f * Mathf.Sin(num * (float)Math.PI) + num * 0.2f + 0.09f * num2 * num2 + ((i == 0) ? 0.035f : (-0.035f)));
					}
				}
			}
			return array;
		}

		internal static int[] PetalTriangles()
		{
			List<int> list = new List<int>();
			for (int i = 0; i < 10; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					int num = i * 7 + j;
					int num2 = num + 1;
					int num3 = num2 + 7;
					int num4 = num + 7;
					list.AddRange(new int[12]
					{
						num,
						num2,
						num4,
						num2,
						num3,
						num4,
						num + 77,
						num4 + 77,
						num2 + 77,
						num2 + 77,
						num4 + 77,
						num3 + 77
					});
				}
			}
			List<int> list2 = new List<int>();
			for (int k = 0; k < 7; k++)
			{
				list2.Add(k);
			}
			for (int l = 1; l < 11; l++)
			{
				list2.Add(l * 7 + 7 - 1);
			}
			for (int num5 = 5; num5 >= 0; num5--)
			{
				list2.Add(70 + num5);
			}
			for (int num6 = 9; num6 > 0; num6--)
			{
				list2.Add(num6 * 7);
			}
			for (int m = 0; m < list2.Count; m++)
			{
				int num7 = list2[m];
				int num8 = list2[(m + 1) % list2.Count];
				list.AddRange(new int[6]
				{
					num7,
					num7 + 77,
					num8,
					num8,
					num7 + 77,
					num8 + 77
				});
			}
			return list.ToArray();
		}

		internal static Vector3[] Tendril(float reach)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[12];
			for (int i = 0; i < array.Length; i++)
			{
				float num = (float)i / (float)(array.Length - 1);
				array[i] = new Vector3(0.16f * Mathf.Sin(num * (float)Math.PI), 0.5f + 0.75f * Mathf.Sin(num * (float)Math.PI), num * reach);
			}
			return array;
		}
	}
	internal sealed class PlantLot
	{
		internal readonly int Number;

		internal readonly string UID;

		internal readonly string Sector;

		internal readonly Vector3 Position;

		internal readonly PlantVariant Variant;

		internal static readonly PlantLot[] All = new PlantLot[7]
		{
			new PlantLot(1, -1465f, 255f, -168f),
			new PlantLot(2, -1572f, 255f, -86f),
			new PlantLot(3, -1468f, 255f, -58f),
			new PlantLot(4, -1562f, 255f, -184f),
			new PlantLot(5, -1420f, 255f, -112f),
			new PlantLot(6, -1508f, 255f, -206f),
			new PlantLot(7, -1582f, 255f, -144f, PlantVariant.AmberQueen)
		};

		internal PlantLot(int number, float x, float y, float z, PlantVariant variant = null)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Number = number;
			Variant = variant ?? PlantVariant.Normal;
			UID = "codex.character.flor.predadora.brejo" + ((number == 1) ? "" : ("." + number));
			if (Variant == PlantVariant.AmberQueen)
			{
				UID = "codex.character.flor.predadora.rainha.ambar";
			}
			Position = new Vector3(1783f + x, 255f, 1796.7f + z);
			Sector = "CierzoTutorial";
		}
	}
	internal sealed class PlantVariant
	{
		internal readonly string Name;

		internal readonly float Scale;

		internal readonly float Health;

		internal readonly Color Root;

		internal readonly Color PetalLow;

		internal readonly Color PetalHigh;

		internal readonly Color Vein;

		internal readonly Color Teeth;

		internal readonly Color Maw;

		internal readonly Color Seed;

		internal readonly Color Emission;

		internal readonly Color Glow;

		internal static readonly PlantVariant Normal = new PlantVariant("Flor Predadora do Brejo", 1f, 260f, new Color(0.24f, 0.4f, 0.19f), new Color(0.4f, 0.09f, 0.25f), new Color(0.8f, 0.33f, 0.51f), new Color(0.17f, 0.035f, 0.13f), new Color(0.77f, 0.84f, 0.55f), new Color(0.095f, 0.025f, 0.065f), new Color(0.39f, 0.83f, 0.19f), new Color(0.11f, 0.35f, 0.035f), new Color(0.48f, 0.9f, 0.2f));

		internal static readonly PlantVariant AmberQueen = new PlantVariant("Rainha Ambar do Brejo", 3.2f, 1200f, new Color(0.12f, 0.3f, 0.15f), new Color(0.45f, 0.13f, 0.025f), new Color(1f, 0.64f, 0.13f), new Color(0.19f, 0.045f, 0.012f), new Color(1f, 0.88f, 0.56f), new Color(0.055f, 0.025f, 0.012f), new Color(1f, 0.52f, 0.08f), new Color(0.42f, 0.13f, 0.015f), new Color(1f, 0.59f, 0.17f));

		private PlantVariant(string name, float scale, float health, Color root, Color low, Color high, Color vein, Color teeth, Color maw, Color seed, Color emission, Color glow)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002c: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			Name = name;
			Scale = scale;
			Health = health;
			Root = root;
			PetalLow = low;
			PetalHigh = high;
			Vein = vein;
			Teeth = teeth;
			Maw = maw;
			Seed = seed;
			Emission = emission;
			Glow = glow;
		}

		internal Color PetalPixel(float v, float grain, float vein)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return Color.Lerp(Color.Lerp(PetalLow, PetalHigh, Mathf.Clamp01(v)) * grain, Vein, vein * 0.65f);
		}
	}
	internal sealed class PlantVisual : MonoBehaviour
	{
		private PlantVariant variant = PlantVariant.Normal;

		private readonly List<Object> owned = new List<Object>();

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

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

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

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

		private Material green;

		private Material petal;

		private Material teeth;

		private Material maw;

		private Material seed;

		private Light glow;

		private CapsuleCollider physical;

		private bool dead;

		private readonly float[] lastReach = new float[2] { -1f, -1f };

		private SharedPlantAssets shared;

		internal Transform Head { get; private set; }

		internal Vector3 Muzzle => Head.position + Head.forward * (0.7f * Scale);

		internal float Scale => variant.Scale;

		private T Own<T>(T value) where T : Object
		{
			return shared.Own(value);
		}

		private Material Finish(string name, Color color, float gloss)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return shared.Get<Material>("material:" + name, (Func<Material>)delegate
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				Material val = Own<Material>(new Material(Shader.Find("Standard") ?? Shader.Find("Diffuse")));
				((Object)val).name = name;
				val.color = color;
				val.enableInstancing = true;
				if (val.HasProperty("_Glossiness"))
				{
					val.SetFloat("_Glossiness", gloss);
				}
				return val;
			});
		}

		internal void Build(int layer, PlantVariant appearance = null)
		{
			//IL_0023: 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_0062: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: 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_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_0744: Unknown result type (might be due to invalid IL or missing references)
			//IL_074e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0770: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			variant = appearance ?? PlantVariant.Normal;
			((Component)this).transform.localScale = Vector3.one * Scale;
			shared = SharedPlantAssets.Acquire(variant);
			((Component)this).gameObject.layer = layer;
			green = Finish("Raizes_Vivas", variant.Root, 0.18f);
			string bark = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "Assets", "bark_diffuse.png");
			if (File.Exists(bark))
			{
				Texture2D mainTexture = shared.Get<Texture2D>("texture:bark", (Func<Texture2D>)delegate
				{
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Expected O, but got Unknown
					Texture2D val3 = Own<Texture2D>(new Texture2D(2, 2, (TextureFormat)3, true));
					if (!ImageConversion.LoadImage(val3, File.ReadAllBytes(bark)) || ((Texture)val3).width > 1024 || ((Texture)val3).height > 1024)
					{
						throw new InvalidDataException("Textura bark fora do limite1K");
					}
					((Texture)val3).wrapMode = (TextureWrapMode)0;
					return val3;
				});
				green.mainTexture = (Texture)(object)mainTexture;
			}
			petal = Finish("Petalas_Rosadas_Veios", Color.white, 0.3f);
			petal.mainTexture = (Texture)(object)PetalTexture();
			teeth = Finish("Espinhos_Marfim", variant.Teeth, 0.25f);
			maw = Finish("Boca_Profunda", variant.Maw, 0.4f);
			seed = Finish("Semente_Venenosa", variant.Seed, 0.5f);
			seed.EnableKeyword("_EMISSION");
			seed.SetColor("_EmissionColor", variant.Emission);
			Vector3[] array = (Vector3[])(object)new Vector3[12];
			float[] array2 = new float[12];
			for (int num = 0; num < 12; num++)
			{
				float num2 = (float)num / 11f;
				array[num] = new Vector3(Mathf.Sin(num2 * 3f) * 0.14f, num2 * 2.4f, Mathf.Sin(num2 * 4f) * 0.1f);
				array2[num] = Mathf.Lerp(0.38f, 0.17f, num2);
			}
			Tube("Caule_Organico", ((Component)this).transform, array, array2, green);
			for (int num3 = 0; num3 < 6; num3++)
			{
				Vector3[] array3 = (Vector3[])(object)new Vector3[12];
				float[] array4 = new float[12];
				for (int num4 = 0; num4 < 12; num4++)
				{
					float num5 = (float)num4 / 11f;
					array3[num4] = new Vector3(0f, 0.09f + Mathf.Sin(num5 * (float)Math.PI) * 0.18f, (1f - num5) * 1.75f);
					array4[num4] = Mathf.Lerp(0.025f, 0.27f, num5);
				}
				Tube("Raiz_" + num3, ((Component)this).transform, array3, array4, green).transform.localRotation = Quaternion.Euler(0f, (float)(num3 * 60 + 12), 0f);
			}
			Head = new GameObject("Corola_Animada").transform;
			Head.SetParent(((Component)this).transform, false);
			Head.localPosition = Vector3.up * 2.4f;
			Mesh mesh = MakeMesh("Petala_Fechada", PlantGeometry.PetalVertices(), PlantGeometry.PetalTriangles());
			for (int num6 = 0; num6 < 8; num6++)
			{
				Transform transform = new GameObject("Petala_Pivo_" + num6).transform;
				transform.SetParent(Head, false);
				transform.localRotation = Quaternion.Euler(0f, 0f, (float)(num6 * 45));
				GameObject val = Piece("Petala_" + num6, transform, mesh, petal);
				val.transform.localPosition = Vector3.up * 0.35f;
				petals.Add(val.transform);
			}
			for (int num7 = 0; num7 < 6; num7++)
			{
				GameObject obj = Piece("Folha_Base_" + num7, ((Component)this).transform, mesh, green);
				obj.transform.localPosition = Vector3.up * 0.35f;
				obj.transform.localRotation = Quaternion.Euler(65f, (float)(num7 * 60), 0f);
				obj.transform.localScale = new Vector3(0.8f, 1.15f, 0.8f);
			}
			GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj2).name = "Boca_Interior";
			obj2.transform.SetParent(Head, false);
			obj2.transform.localScale = new Vector3(1.12f, 1.12f, 0.3f);
			Object.Destroy((Object)(object)obj2.GetComponent<Collider>());
			Renderer component = obj2.GetComponent<Renderer>();
			component.sharedMaterial = maw;
			component.shadowCastingMode = (ShadowCastingMode)0;
			renderers.Add(component);
			for (int num8 = 0; num8 < 12; num8++)
			{
				float num9 = (float)num8 * (float)Math.PI * 2f / 12f;
				Vector3[] points = (Vector3[])(object)new Vector3[3]
				{
					new Vector3(Mathf.Cos(num9) * 0.6f, Mathf.Sin(num9) * 0.6f, 0.12f),
					new Vector3(Mathf.Cos(num9) * 0.49f, Mathf.Sin(num9) * 0.49f, 0.28f),
					new Vector3(Mathf.Cos(num9) * 0.37f, Mathf.Sin(num9) * 0.37f, 0.42f)
				};
				Tube("Dente_" + num8, Head, points, new float[3] { 0.09f, 0.07f, 0.009f }, teeth);
			}
			for (int num10 = 0; num10 < 2; num10++)
			{
				Transform transform2 = new GameObject("Tentaculo_Pivo_" + num10).transform;
				transform2.SetParent(((Component)this).transform, false);
				transform2.localPosition = new Vector3((num10 == 0) ? (-0.46f) : 0.46f, 0.1f, 0f);
				float[] radii = TendrilRadii();
				GameObject val2 = Tube("Tentaculo_" + num10, transform2, PlantGeometry.Tendril(2f), radii, green);
				arms.Add(transform2);
				armMeshes.Add(val2.GetComponent<MeshFilter>().sharedMesh);
			}
			physical = ((Component)this).gameObject.AddComponent<CapsuleCollider>();
			physical.radius = 0.6f;
			physical.height = 1.6f;
			physical.center = Vector3.up * 0.8f;
			glow = new GameObject("Brilho_Boca").AddComponent<Light>();
			((Component)glow).transform.SetParent(Head, false);
			((Component)glow).transform.localPosition = Vector3.forward * 0.5f;
			glow.type = (LightType)2;
			glow.color = variant.Glow;
			glow.range = 3f * Scale;
			glow.intensity = 0.45f;
			glow.shadows = (LightShadows)0;
		}

		private float[] TendrilRadii()
		{
			float[] array = new float[12];
			for (int i = 0; i < 12; i++)
			{
				array[i] = Mathf.Lerp(0.16f, 0.025f, (float)i / 11f);
			}
			return array;
		}

		private GameObject Tube(string name, Transform parent, Vector3[] points, float[] radii, Material mat)
		{
			return Piece(name, parent, MakeMesh(name, PlantGeometry.Tube(points, radii), PlantGeometry.TubeTriangles(points.Length)), mat);
		}

		private GameObject Piece(string name, Transform parent, Mesh mesh, Material mat)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			((Renderer)val2).sharedMaterial = mat;
			((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
			renderers.Add((Renderer)(object)val2);
			return val;
		}

		private Mesh MakeMesh(string name, Vector3[] p, int[] triangles)
		{
			if (!name.StartsWith("Tentaculo_", StringComparison.Ordinal))
			{
				return shared.Get<Mesh>("mesh:" + name, (Func<Mesh>)(() => CreateMesh(name, p, triangles, dynamic: false)));
			}
			return CreateMesh(name, p, triangles, dynamic: true);
		}

		private Mesh CreateMesh(string name, Vector3[] p, int[] triangles, bool dynamic)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh
			{
				name = name
			};
			if (dynamic)
			{
				owned.Add((Object)(object)val);
			}
			else
			{
				Own<Mesh>(val);
			}
			val.vertices = p;
			val.triangles = triangles;
			Vector2[] array = (Vector2[])(object)new Vector2[p.Length];
			for (int i = 0; i < p.Length; i++)
			{
				array[i] = new Vector2(p[i].x * 0.6f + 0.5f, p[i].y * 0.6f);
			}
			val.uv = array;
			val.RecalculateNormals();
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
		}

		private Texture2D PetalTexture()
		{
			return shared.Get<Texture2D>("texture:petal", (Func<Texture2D>)CreatePetalTexture);
		}

		private Texture2D CreatePetalTexture()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = Own<Texture2D>(new Texture2D(512, 512, (TextureFormat)3, true));
			Color[] array = (Color[])(object)new Color[262144];
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 512; j++)
				{
					float num = (float)j / 512f;
					float num2 = (float)i / 512f;
					float grain = 0.75f + 0.25f * Mathf.PerlinNoise(num * 85f, num2 * 67f);
					float vein = Mathf.Pow(Mathf.Abs(Mathf.Sin((num - 0.5f) * 80f + num2 * 15f)), 14f);
					array[i * 512 + j] = variant.PetalPixel(num2, grain, vein);
				}
			}
			((Object)val).name = "Petalas_Veios_512";
			val.SetPixels(array);
			val.Apply(true, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			return val;
		}

		internal void Pose(PlantPhase phase, float progress, int combo, float time)
		{
			//IL_0014: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			if (dead)
			{
				Head.localRotation = Quaternion.Slerp(Head.localRotation, Quaternion.Euler(70f, 0f, 20f), Time.deltaTime * 2f);
				return;
			}
			float num = ((phase == PlantPhase.SeedWarning) ? progress : ((float)((phase == PlantPhase.Volley) ? 1 : 0)));
			Head.localScale = Vector3.one * (1f + 0.025f * Mathf.Sin(time * 2.2f) + num * 0.13f);
			foreach (Transform petal in petals)
			{
				petal.localRotation = Quaternion.Euler(-12f - num * 24f, 0f, 0f);
			}
			glow.intensity = 0.4f + num * 1.6f;
			for (int i = 0; i < 2; i++)
			{
				float num2 = 2f;
				if (i == combo)
				{
					if (phase == PlantPhase.Whip)
					{
						num2 = 1.6f + 2.65f * Mathf.Sin(progress * (float)Math.PI);
					}
					if (phase == PlantPhase.WhipWarning)
					{
						num2 = 2f - 0.4f * progress;
					}
					if (phase == PlantPhase.Recover)
					{
						num2 = 1.6f + 0.4f * progress;
					}
				}
				if (Mathf.Abs(num2 - lastReach[i]) > 0.02f)
				{
					armMeshes[i].vertices = PlantGeometry.Tube(PlantGeometry.Tendril(num2), TendrilRadii());
					armMeshes[i].RecalculateNormals();
					armMeshes[i].RecalculateBounds();
					lastReach[i] = num2;
				}
				float num3 = (float)((i != 0) ? 1 : (-1)) * (52f + Mathf.Sin(time * 0.8f + (float)i) * 5f);
				if (phase == PlantPhase.WhipWarning && i == combo)
				{
					num3 = ((combo == 0) ? (-85) : 85);
				}
				if (phase == PlantPhase.Whip && i == combo)
				{
					num3 = Mathf.Lerp((float)((combo == 0) ? (-85) : 85), (float)((combo == 0) ? 55 : (-55)), progress);
				}
				arms[i].localRotation = Quaternion.Euler(0f, num3, 0f);
			}
		}

		internal void Face(Vector3 direction, float delta)
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			direction.y = 0f;
			if (((Vector3)(ref direction)).sqrMagnitude > 0.01f && !dead)
			{
				((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(direction), 100f * delta);
			}
		}

		internal Vector3 TendrilDirection(int combo)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return arms[combo].forward;
		}

		internal float TendrilReach(int combo)
		{
			return lastReach[combo] * Scale;
		}

		internal GameObject Seed(Vector3 position)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj).name = "Flor_Semente_Projetil";
			obj.transform.position = position;
			obj.transform.localScale = new Vector3(0.2f, 0.2f, 0.32f);
			obj.GetComponent<Collider>().enabled = false;
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			Renderer component = obj.GetComponent<Renderer>();
			component.sharedMaterial = seed;
			component.shadowCastingMode = (ShadowCastingMode)0;
			return obj;
		}

		internal void Visible(bool show)
		{
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = show;
				}
			}
			if ((Object)(object)glow != (Object)null)
			{
				((Behaviour)glow).enabled = show && !dead;
			}
		}

		internal void Die()
		{
			dead = true;
			if ((Object)(object)physical != (Object)null)
			{
				((Collider)physical).enabled = false;
			}
			if ((Object)(object)glow != (Object)null)
			{
				((Behaviour)glow).enabled = false;
			}
		}

		private void OnDestroy()
		{
			foreach (Object item in owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			owned.Clear();
			shared?.Release();
			shared = null;
		}
	}
	[BepInPlugin("codex.outward.flor.predadora", "Codex - Flor Predadora do Brejo", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Slot
		{
			internal readonly PlantLot Lot;

			internal SL_Character Template;

			internal Character Body;

			internal GameObject Actor;

			internal bool Creating;

			internal bool Visited;

			internal int Generation;

			internal float NextAttempt;

			internal float NextWarning;

			internal Slot(PlantLot lot)
			{
				Lot = lot;
			}
		}

		public const string Guid = "codex.outward.flor.predadora";

		internal static Plugin Instance;

		internal static readonly Vector3 Position = PlantLot.All[0].Position;

		private readonly Slot[] slots = Array.ConvertAll(PlantLot.All, (PlantLot lot) => new Slot(lot));

		private float nextScan;

		private ConfigEntry<KeyboardShortcut> reset;

		internal ConfigEntry<bool> Detailed;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			reset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Teste", "Recriar", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "F10 perto da flor (ate15m) recria somente ela.");
			Detailed = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostico", "Detalhado", false, "Registra acertos/bloqueios individuais;spawn/morte/erros sempre registrados.");
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += SceneLoaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			Message("1.4.0:6 flores+Rainha em " + PlantLot.All[0].Sector + ";veneno100%;F10 recria a mais proxima ate15m.");
		}

		private void Prepare()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0142: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			Slot[] array = slots;
			foreach (Slot slot in array)
			{
				if (slot.Template == null)
				{
					slot.Template = new SL_Character
					{
						UID = slot.Lot.UID,
						Name = slot.Lot.Variant.Name,
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						DestroyOnDeath = false,
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						Faction = (Factions)9,
						CharacterVisualsData = new VisualData(),
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = -1,
						Boots_ID = -1,
						Backpack_ID = -1,
						Health = slot.Lot.Variant.Health,
						HealthRegen = 0f,
						Protection = 0f,
						Barrier = 0f,
						ImpactResist = 100f,
						Damage_Resists = new float[9],
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false
					};
					((ContentTemplate)slot.Template).ApplyTemplate();
				}
			}
			Message("7templates temporarios preparados:6normais+1Rainha;UIDs exclusivos;sem loot/sem mob antigo reativado.");
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				((MonoBehaviour)this).StopAllCoroutines();
				Slot[] array = slots;
				foreach (Slot slot in array)
				{
					Cleanup(slot);
					slot.Visited = false;
					slot.NextAttempt = 0f;
				}
				nextScan = 0f;
			}
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != PlantLot.All[0].Sector || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = reset.Value;
			Slot[] array;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Slot slot = null;
				float num = 225f;
				array = slots;
				foreach (Slot slot2 in array)
				{
					Character val = Nearest(slot2.Lot.Position, 15f);
					if (!((Object)(object)val == (Object)null) && (!((Object)(object)val.CharacterUI != (Object)null) || !val.CharacterUI.IsMenuFocused))
					{
						Vector3 val2 = val.CenterPosition - slot2.Lot.Position;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							slot = slot2;
						}
					}
				}
				if (slot != null)
				{
					Cleanup(slot);
					slot.Visited = false;
					slot.NextAttempt = 0f;
					int i = slot.Lot.Number;
					Message("F10 somente flor " + i);
				}
			}
			if (Time.realtimeSinceStartup < nextScan)
			{
				return;
			}
			nextScan = Time.realtimeSinceStartup + 0.25f;
			array = slots;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Creating)
				{
					return;
				}
			}
			array = slots;
			foreach (Slot slot3 in array)
			{
				if (slot3.Template != null && !slot3.Visited && !(Time.realtimeSinceStartup < slot3.NextAttempt) && !((Object)(object)Nearest(slot3.Lot.Position, 150f) == (Object)null))
				{
					if (TryFloor(slot3.Lot, out var surface, out var support, out var reason))
					{
						((MonoBehaviour)this).StartCoroutine(Create(slot3, surface, support, slot3.Generation));
						break;
					}
					if (Time.realtimeSinceStartup >= slot3.NextWarning)
					{
						int number = slot3.Lot.Number;
						Message("FLOR " + number + " AGUARDANDO piso/espaco real: " + reason);
						slot3.NextWarning = Time.realtimeSinceStartup + 15f;
					}
					slot3.NextAttempt = Time.realtimeSinceStartup + 2f;
				}
			}
		}

		private unsafe IEnumerator Create(Slot slot, Vector3 floor, Collider support, int token)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			slot.Creating = true;
			try
			{
				slot.Body = slot.Template.Spawn(floor + Vector3.up * 0.08f, (string)null, (string)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[FlorPredadora] Receptor nativo: " + ex));
			}
			Character body = slot.Body;
			if ((Object)(object)body == (Object)null)
			{
				slot.Creating = false;
				slot.NextAttempt = Time.realtimeSinceStartup + 5f;
				yield break;
			}
			((Component)body).gameObject.AddComponent<HiddenPlantReceiver>();
			float deadline = Time.realtimeSinceStartup + 25f;
			while (token == slot.Generation && (Object)(object)body != (Object)null && ((Object)(object)body.Stats == (Object)null || (Object)(object)body.Animator == (Object)null || body.Hitboxes == null || body.Hitboxes.Length == 0) && Time.realtimeSinceStartup < deadline)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (token != slot.Generation)
			{
				yield break;
			}
			if ((Object)(object)body == (Object)null)
			{
				slot.Creating = false;
				slot.NextAttempt = Time.realtimeSinceStartup + 5f;
				yield break;
			}
			try
			{
				if ((Object)(object)body.Stats == (Object)null || (Object)(object)body.Animator == (Object)null || body.Hitboxes == null || body.Hitboxes.Length == 0)
				{
					throw new InvalidOperationException("Receptor nativo nao inicializado;sera tentado novamente");
				}
				body.Teleport(floor + Vector3.up * 0.08f, Quaternion.identity);
				body.Invincible = false;
				body.QuestInvicibility = false;
				body.QuestNonTargetable = false;
				body.Stats.SetHealth(slot.Lot.Variant.Health);
				int number = slot.Lot.Number;
				slot.Actor = new GameObject("Codex_Flor_Predadora_Custom_" + number);
				slot.Actor.transform.position = floor;
				PlantVisual plantVisual = slot.Actor.AddComponent<PlantVisual>();
				plantVisual.Build(((Component)support).gameObject.layer, slot.Lot.Variant);
				((Component)body).gameObject.AddComponent<PlantEnemy>().Initialize(body, plantVisual, floor);
				slot.Visited = true;
				Plugin plugin = this;
				string[] obj = new string[15]
				{
					"FLOR ", null, null, null, null, null, null, null, null, null,
					null, null, null, null, null
				};
				number = slot.Lot.Number;
				obj[1] = number.ToString();
				obj[2] = " PRONTA: ";
				Vector3 val = floor;
				obj[3] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				obj[4] = ";nome=";
				obj[5] = slot.Lot.Variant.Name;
				obj[6] = ";UID=";
				obj[7] = slot.Lot.UID;
				obj[8] = ";apoio=";
				obj[9] = ((Object)support).name;
				obj[10] = ";vida=";
				float health = slot.Lot.Variant.Health;
				obj[11] = health.ToString();
				obj[12] = ";escala=";
				health = slot.Lot.Variant.Scale;
				obj[13] = health.ToString();
				obj[14] = ";receptor nativo/mira TAB;30m;sem gateNavMesh.";
				plugin.Message(string.Concat(obj));
			}
			catch (Exception ex2)
			{
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				int number = slot.Lot.Number;
				logger.LogError((object)("[FlorPredadora] Flor " + number + " setup falhou;mapa preservado: " + ex2));
				Cleanup(slot);
				slot.NextAttempt = Time.realtimeSinceStartup + 5f;
			}
			slot.Creating = false;
		}

		private static bool TryFloor(PlantLot lot, out Vector3 surface, out Collider support, out string reason)
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			surface = lot.Position;
			support = null;
			reason = "Piso firme ausente";
			RaycastHit[] array = Physics.RaycastAll(new Ray(lot.Position + Vector3.up * 7f, Vector3.down), 17f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!((Object)(object)collider == (Object)null) && collider.enabled && !collider.isTrigger && !(((RaycastHit)(ref val)).normal.y < 0.7f) && !(Mathf.Abs(((RaycastHit)(ref val)).point.y - lot.Position.y) > 4f) && !((Object)collider).name.ToLowerInvariant().Contains("water") && ((Object)(object)support == (Object)null || Mathf.Abs(((RaycastHit)(ref val)).point.y - lot.Position.y) < Mathf.Abs(surface.y - lot.Position.y)))
				{
					surface = ((RaycastHit)(ref val)).point;
					support = collider;
				}
			}
			if ((Object)(object)support == (Object)null)
			{
				return false;
			}
			float scale = lot.Variant.Scale;
			Collider[] array2 = Physics.OverlapCapsule(surface + Vector3.up * (1.4f * scale), surface + Vector3.up * (3.2f * scale), 1.2f * scale, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)support)
				{
					reason = "Lote bloqueado por " + ((Object)val2).name;
					return false;
				}
			}
			reason = null;
			return true;
		}

		internal static Character Nearest(Vector3 point, float radius)
		{
			//IL_0059: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			CharacterManager instance = CharacterManager.Instance;
			if (((instance != null) ? instance.Characters : null) == null)
			{
				return null;
			}
			Character result = null;
			float num = radius * radius;
			foreach (Character value in CharacterManager.Instance.Characters.Values)
			{
				if (!((Object)(object)value == (Object)null) && value.IsLocalPlayer && value.Alive && !(Mathf.Abs(((Component)value).transform.position.y - point.y) > 12f))
				{
					Vector3 val = value.CenterPosition - point;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = value;
					}
				}
			}
			return result;
		}

		internal void Message(string text)
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[FlorPredadora] " + text));
		}

		private void Cleanup(Slot slot)
		{
			slot.Generation++;
			if ((Object)(object)slot.Body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(slot.Body);
			}
			if ((Object)(object)slot.Actor != (Object)null)
			{
				Object.Destroy((Object)(object)slot.Actor);
			}
			slot.Body = null;
			slot.Actor = null;
			slot.Creating = false;
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= SceneLoaded;
			((MonoBehaviour)this).StopAllCoroutines();
			Slot[] array = slots;
			foreach (Slot slot in array)
			{
				Cleanup(slot);
				if (slot.Template != null)
				{
					slot.Template.Unregister();
				}
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	internal sealed class SharedPlantAssets
	{
		private static readonly Dictionary<PlantVariant, SharedPlantAssets> groups = new Dictionary<PlantVariant, SharedPlantAssets>();

		private readonly PlantVariant key;

		private readonly HashSet<Object> owned = new HashSet<Object>();

		private readonly Dictionary<string, Object> cached = new Dictionary<string, Object>();

		private int references;

		public static string Summary
		{
			get
			{
				int num = 0;
				int num2 = 0;
				foreach (SharedPlantAssets value in groups.Values)
				{
					num += value.references;
					num2 += value.owned.Count;
				}
				return "paletas=" + groups.Count + ";flores=" + num + ";recursosCompartilhados=" + num2 + ";tentaculosDinamicosIndividuais";
			}
		}

		private SharedPlantAssets(PlantVariant variant)
		{
			key = variant;
		}

		internal static SharedPlantAssets Acquire(PlantVariant variant)
		{
			if (!groups.TryGetValue(variant, out var value))
			{
				value = new SharedPlantAssets(variant);
				groups.Add(variant, value);
			}
			value.references++;
			return value;
		}

		internal T Own<T>(T value) where T : Object
		{
			owned.Add((Object)(object)value);
			return value;
		}

		internal T Get<T>(string id, Func<T> create) where T : Object
		{
			if (cached.TryGetValue(id, out var value))
			{
				return (T)(object)value;
			}
			T val = create();
			cached.Add(id, (Object)(object)val);
			return val;
		}

		internal void Release()
		{
			if (references <= 0 || --references > 0)
			{
				return;
			}
			foreach (Object item in owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			owned.Clear();
			cached.Clear();
			groups.Remove(key);
		}
	}
}

BepInEx/plugins/Codex_Gelo_Cinzas/CodexGeloCinzas.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexHumanoidExtras;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexGeloCinzas
{
	internal sealed class ExternalClip
	{
		internal const string IcePrefix = "CodexPrisaoHumanoid_";

		internal const string AshPrefix = "CodexCinzasHumanoid_";

		internal readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private readonly List<AnimationClip> copies = new List<AnimationClip>();

		private AssetBundle bundle;

		internal float Duration { get; private set; }

		internal bool Ready => Overrides.Count == 3;

		internal unsafe void Build(string folder, string bundleName, string clipName, string prefix, string expectedHash)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", bundleName);
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != expectedHash)
					{
						throw new InvalidDataException("External Humanoid bundle SHA mismatch: " + bundleName);
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("External bundle unavailable: " + bundleName);
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == clipName);
				if (val.legacy || !((Motion)val).isHumanMotion || val.length < 0.3f || val.length > 8f)
				{
					throw new InvalidDataException("Not a valid Humanoid motion: " + clipName);
				}
				Duration = val.length;
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = prefix + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
			Duration = 0f;
		}
	}
	public sealed class FieldArea : MonoBehaviour
	{
		private const float IceLifetime = 5f;

		private const float AshLifetime = 8f;

		private const float AshRadius = 3.2f;

		private Character owner;

		private bool ice;

		private float age;

		private float nextTick;

		private Vector3 ground;

		internal void Bind(Character caster, Vector3 point, bool isIce)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			owner = caster;
			ice = isIce;
			ground = point;
			((Component)this).transform.position = point;
			if (ice)
			{
				FieldVisual.IceWall(((Component)this).transform, point);
				FieldVisual.Sound((Sounds)13121, point);
			}
			else
			{
				FieldVisual.NativeFire(((Component)this).transform);
				FieldVisual.Sound((Sounds)13042, point);
				nextTick = 1f;
			}
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				age += Time.deltaTime;
				if (!ice)
				{
					while (nextTick <= 8f && age >= nextTick)
					{
						Burn();
						nextTick += 1f;
					}
				}
				if (age >= (ice ? 5f : 8f))
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private void Burn()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			int num = 0;
			HashSet<Character> hashSet = new HashSet<Character>();
			Collider[] array = Physics.OverlapSphere(ground + Vector3.up * 0.85f, 3.2f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox componentInParent = ((Component)array[i]).GetComponentInParent<Hitbox>();
				Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
				if (!((Object)(object)val == (Object)null) && hashSet.Add(val) && !((Object)(object)val == (Object)(object)owner) && val.Alive && !val.Invincible && !val.IsLocalPlayer && !((Object)(object)owner.TargetingSystem == (Object)null) && owner.TargetingSystem.IsTargetable(val) && !(Mathf.Abs(val.CenterPosition.y - ground.y) > 2.3f) && !Physics.Linecast(ground + Vector3.up * 0.8f, val.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
				{
					Vector3 val2 = val.CenterPosition - owner.CenterPosition;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					val.ReceiveHit((Object)null, new DamageList((Types)5, 15f), normalized, val.CenterPosition, 35f, 1f, owner, 0f, true);
					num++;
				}
			}
			if (num > 0)
			{
				FieldVisual.Sound((Sounds)12980, ground);
			}
			Plugin.Log.LogMessage((object)("[GeloCinzas] CINZAS_TICK:" + nextTick + ";hits=" + num));
		}
	}
	public sealed class FieldMotion : MonoBehaviour
	{
		private Character player;

		private Character target;

		private Avatar avatar;

		private Skill skill;

		private ExternalClip clip;

		private OverrideLease lease;

		private PlaybackTail tail;

		private float normalized;

		private bool nativeCast;

		private bool released;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal static bool Our(int id)
		{
			if (id != 9106980)
			{
				return id == 9106990;
			}
			return true;
		}

		internal bool CanBegin(int id)
		{
			if (!Our(id) || Active || HasVisibleLease || (Object)(object)player == (Object)null || !player.IsLocalPlayer || !player.Alive || player.Falling || player.Sliding || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				return false;
			}
			if (id != 9106990)
			{
				if (Plugin.IceClip.Ready)
				{
					return (Object)(object)FieldTarget.Find(player) != (Object)null;
				}
				return false;
			}
			return Plugin.AshClip.Ready;
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
		}

		internal bool Begin(Skill value)
		{
			if (!CanBegin(((Item)value).ItemID))
			{
				return false;
			}
			try
			{
				target = ((((Item)value).ItemID == 9106980) ? FieldTarget.Find(player) : FieldTarget.Find(player));
				clip = ((((Item)value).ItemID == 9106980) ? Plugin.IceClip : Plugin.AshClip);
				lease = new OverrideLease(delegate(int i, bool on)
				{
					clip.Overrides[i].SetForCharacter(player, on);
				});
				lease.Acquire(clip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				normalized = 0f;
				nativeCast = (released = false);
				Plugin.Log.LogMessage((object)("[GeloCinzas] CAST:" + ((Item)value).ItemID + ";Human=True;nativeAvatar=" + ((Object)avatar).name));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && (Object)(object)value == (Object)(object)skill && !tail.NativeEnded)
			{
				tail.EndNative();
			}
		}

		private void LateUpdate()
		{
			//IL_00f7: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				bool observed = tail.Observed;
				string prefix = ((((Item)skill).ItemID == 9106980) ? "CodexPrisaoHumanoid_" : "CodexCinzasHumanoid_");
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime, prefix);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime, prefix);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (!observed && tail.Observed)
				{
					Plugin.Log.LogMessage((object)("[GeloCinzas] EXTERNALACTIVE:" + ((Item)skill).ItemID + ";AvatarUNCHANGED"));
				}
				try
				{
					if (flag && normalized >= 0.025f && !nativeCast)
					{
						if (!OwnCast)
						{
							Fail("Native receiver lost before cost");
							return;
						}
						NativeInvocation = true;
						nativeCast = true;
						((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
						NativeInvocation = false;
						if (!Active || !OwnCast)
						{
							return;
						}
					}
					if (nativeCast && !released && ((flag && normalized >= 0.34f) || tail.CanRestore))
					{
						ReleaseField();
					}
				}
				catch (Exception ex)
				{
					Fail("RELEASEFAILED:" + ex);
					return;
				}
				finally
				{
					NativeInvocation = false;
				}
				if (tail.CanRestore)
				{
					Cancel("native blend-out complete");
				}
				else if (tail.TimedOut(clip.Duration))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress, string prefix)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith(prefix, StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private unsafe void ReleaseField()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			released = true;
			bool flag = ((Item)skill).ItemID == 9106980;
			if (flag && !FieldTarget.Valid(player, target))
			{
				Plugin.Log.LogMessage((object)"[GeloCinzas] TARGET_LOST;no prison");
				return;
			}
			Vector3 val = (flag ? FieldTarget.Ground(target) : FieldTarget.AshGround(player, target));
			new GameObject(flag ? "Codex_Prisao_Gelo" : "Codex_Ritual_Cinzas").AddComponent<FieldArea>().Bind(player, val, flag);
			ManualLogSource log = Plugin.Log;
			string text = ((Item)skill).ItemID.ToString();
			Vector3 val2 = val;
			log.LogMessage((object)("[GeloCinzas] RELEASE:" + text + ";point=" + ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString()));
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[GeloCinzas] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			bool active = Active;
			skill = null;
			target = null;
			tail = null;
			nativeCast = (released = false);
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[GeloCinzas] RESTORED;reason=" + reason + ";AvatarUNCHANGED"));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[GeloCinzas] RESTOREFAILED:" + ex));
			}
			if (lease == null || !lease.Active)
			{
				lease = null;
				clip = null;
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal static class FieldTarget
	{
		private const float Range = 15f;

		internal static Character Find(Character owner)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)owner == (Object)null || (Object)(object)owner.TargetingSystem == (Object)null)
			{
				return null;
			}
			Character lockedCharacter = owner.TargetingSystem.LockedCharacter;
			if (Valid(owner, lockedCharacter))
			{
				return lockedCharacter;
			}
			Character result = null;
			float num = float.MaxValue;
			HashSet<Character> hashSet = new HashSet<Character>();
			Collider[] array = Physics.OverlapSphere(owner.CenterPosition, 15f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox componentInParent = ((Component)array[i]).GetComponentInParent<Hitbox>();
				Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
				if (hashSet.Add(val) && Valid(owner, val))
				{
					Vector3 val2 = val.CenterPosition - owner.CenterPosition;
					float num2 = Vector3.Angle(((Component)owner).transform.forward, val2) * 0.13f + ((Vector3)(ref val2)).magnitude;
					if (num2 < num)
					{
						result = val;
						num = num2;
					}
				}
			}
			return result;
		}

		internal static bool Valid(Character owner, Character target)
		{
			//IL_0052: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)owner == (Object)null || (Object)(object)target == (Object)null || (Object)(object)target == (Object)(object)owner || !target.Alive || target.Invincible || target.IsLocalPlayer || (Object)(object)owner.TargetingSystem == (Object)null || !owner.TargetingSystem.IsTargetable(target))
			{
				return false;
			}
			Vector3 val = target.CenterPosition - owner.CenterPosition;
			if (((Vector3)(ref val)).sqrMagnitude <= 225f && Vector3.Angle(((Component)owner).transform.forward, val) <= 55f)
			{
				return !Physics.Linecast(owner.CenterPosition, target.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			}
			return false;
		}

		internal static Vector3 Ground(Character target)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(((Component)target).transform.position + Vector3.up * 1.8f, Vector3.down, ref val, 4f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				return ((Component)target).transform.position;
			}
			return ((RaycastHit)(ref val)).point;
		}

		internal static Vector3 AshGround(Character owner, Character target)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Valid(owner, target) ? Ground(target) : (((Component)owner).transform.position + ((Component)owner).transform.forward * 5f));
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val + Vector3.up * 3f, Vector3.down, ref val2, 7f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				return val;
			}
			return ((RaycastHit)(ref val2)).point;
		}
	}
	internal static class FieldVisual
	{
		private static Material frost;

		private static readonly Mesh[] iceMeshes = (Mesh[])(object)new Mesh[14];

		private static Sprite iceIcon;

		private static Sprite ashIcon;

		private static Texture2D iceTexture;

		private static Texture2D ashTexture;

		internal static void Ensure()
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			if (!((Object)(object)frost != (Object)null))
			{
				Shader obj = Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse");
				if ((Object)(object)obj == (Object)null)
				{
					throw new InvalidOperationException("Ice shader unavailable");
				}
				frost = new Material(obj)
				{
					name = "Codex_Gelo_Opaco",
					color = new Color(0.48f, 0.77f, 0.86f, 1f)
				};
			}
		}

		internal static void IceWall(Transform root, Vector3 center)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00eb: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i < 14; i++)
			{
				float num = (float)(i * 2) * (float)Math.PI / 14f;
				float num2 = Mathf.Sin((float)i * 13.29f) * 0.13f;
				Vector3 val = center + new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * (2.15f + num2);
				Vector3 position = (Physics.Raycast(val + Vector3.up * 2f, Vector3.down, ref val2, 5f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1) ? ((RaycastHit)(ref val2)).point : val);
				float num3 = 1.8f + (0.5f + 0.5f * Mathf.Sin((float)i * 4.9f)) * 1.05f;
				GameObject val3 = new GameObject("Gelo_Estalagmite_" + i);
				val3.transform.SetParent(root, true);
				val3.transform.position = position;
				val3.transform.rotation = Quaternion.Euler(0f, (0f - num) * 57.29578f - 90f, 0f);
				val3.AddComponent<MeshFilter>().sharedMesh = iceMeshes[i] ?? (iceMeshes[i] = ShardMesh(0.58f, num3, i));
				((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = frost;
				BoxCollider obj = val3.AddComponent<BoxCollider>();
				obj.center = new Vector3(0f, num3 * 0.46f, 0f);
				obj.size = new Vector3(1.08f, num3 * 0.92f, 0.62f);
			}
		}

		private static Mesh ShardMesh(float width, float height, int index)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			Vector3[] array = (Vector3[])(object)new Vector3[15];
			int[] array2 = new int[63];
			for (int i = 0; i < 7; i++)
			{
				float num = (float)(i * 2) * (float)Math.PI / 7f;
				float num2 = 0.84f + 0.16f * Mathf.Sin((float)index * 3.1f + (float)i * 5.3f);
				array[i] = new Vector3(Mathf.Cos(num) * width * num2, 0f, Mathf.Sin(num) * width * 0.72f * num2);
				array[7 + i] = new Vector3(Mathf.Cos(num) * width * 0.43f, height * 0.54f, Mathf.Sin(num) * width * 0.31f);
			}
			array[14] = new Vector3(Mathf.Sin((float)index * 2.7f) * 0.22f, height, Mathf.Cos((float)index * 3.5f) * 0.15f);
			int num3 = 0;
			for (int j = 0; j < 7; j++)
			{
				int num4 = (j + 1) % 7;
				array2[num3++] = j;
				array2[num3++] = 7 + j;
				array2[num3++] = num4;
				array2[num3++] = num4;
				array2[num3++] = 7 + j;
				array2[num3++] = 7 + num4;
				array2[num3++] = 7 + j;
				array2[num3++] = 14;
				array2[num3++] = 7 + num4;
			}
			Mesh val = new Mesh
			{
				name = "Gelo_Irregular",
				vertices = array,
				triangles = array2
			};
			val.RecalculateNormals();
			return val;
		}

		internal static void NativeFire(Transform root)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = FindNativeVfx("FireLinger");
			bool upward = false;
			string text = "FireLinger";
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[GeloCinzas] FIRE_VFX_MISSING:FireLinger;using native Flamethrower_FXFire");
				val = SL_PlayVFX.GetVfxSystem((VFXPrefabs)12);
				upward = (Object)(object)val != (Object)null;
				text = "Flamethrower_FXFire";
			}
			if ((Object)(object)val == (Object)null)
			{
				val = SL_PlayVFX.GetVfxSystem((VFXPrefabs)62);
				text = "VFXBoonFire";
				Plugin.Log.LogWarning((object)"[GeloCinzas] FIRE_VFX_MISSING:Flamethrower_FXFire;using native VFXBoonFire");
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"[GeloCinzas] FIRE_VFX_MISSING:all native fire prefabs");
				return;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[3]
			{
				Vector3.zero,
				new Vector3(1.3f, 0f, 0.65f),
				new Vector3(-1.15f, 0f, -0.95f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				SpawnNative(val, root, text + "_" + i, array[i], (i == 0) ? 1.05f : 0.78f, loop: true, i == 0, 0f, upward);
			}
			GameObject val2 = FindNativeVfx("BurningBlast");
			if ((Object)(object)val2 != (Object)null)
			{
				SpawnNative(val2, root, "BurningBlast_Opening", Vector3.zero, 0.75f, loop: false, lightAllowed: false, 1.7f, upward: false);
			}
			else
			{
				Plugin.Log.LogWarning((object)"[GeloCinzas] FIRE_VFX_MISSING:BurningBlast");
			}
			Plugin.Log.LogMessage((object)("[GeloCinzas] NATIVE_FIRE;prefab=" + text + ";instances=3;BurningBlast=" + ((Object)(object)val2 != (Object)null)));
		}

		private static GameObject FindNativeVfx(string name)
		{
			VFXSystem[] array = Resources.FindObjectsOfTypeAll<VFXSystem>();
			foreach (VFXSystem val in array)
			{
				if ((Object)(object)val != (Object)null && string.Equals(((Object)((Component)val).gameObject).name.Replace("(Clone)", "").Replace(" ", "").Replace("_", ""), name, StringComparison.OrdinalIgnoreCase))
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private static void SpawnNative(GameObject prefab, Transform root, string name, Vector3 offset, float scale, bool loop, bool lightAllowed, float lifetime, bool upward)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = (upward ? Quaternion.Euler(-90f, 0f, 0f) : Quaternion.identity);
			GameObject val2 = Object.Instantiate<GameObject>(prefab, root.position + offset + Vector3.up * 0.06f, val);
			((Object)val2).name = "Codex_" + name;
			val2.transform.SetParent(root, true);
			Transform transform = val2.transform;
			transform.localScale *= scale;
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Projectile[] componentsInChildren2 = val2.GetComponentsInChildren<Projectile>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Behaviour)componentsInChildren2[i]).enabled = false;
			}
			Blast[] componentsInChildren3 = val2.GetComponentsInChildren<Blast>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				((Behaviour)componentsInChildren3[i]).enabled = false;
			}
			Light[] componentsInChildren4 = val2.GetComponentsInChildren<Light>(true);
			foreach (Light obj in componentsInChildren4)
			{
				((Behaviour)obj).enabled = lightAllowed;
				obj.shadows = (LightShadows)0;
				obj.range = Mathf.Min(obj.range, 5.5f);
				obj.intensity = Mathf.Min(obj.intensity, 1.4f);
			}
			val2.SetActive(true);
			VFXSystem[] componentsInChildren5 = val2.GetComponentsInChildren<VFXSystem>(true);
			foreach (VFXSystem val3 in componentsInChildren5)
			{
				try
				{
					val3.Play((Character)null, (Character)null);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("[GeloCinzas] FIRE_VFX_PLAY:" + name + ":" + ex.Message));
				}
			}
			int num = 0;
			ParticleSystem[] componentsInChildren6 = val2.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem obj2 in componentsInChildren6)
			{
				MainModule main = obj2.main;
				((MainModule)(ref main)).loop = loop;
				obj2.Play(true);
				num++;
			}
			Plugin.Log.LogMessage((object)("[GeloCinzas] FIRE_VFX_SPAWN:" + name + ";particles=" + num));
			if (lifetime > 0f)
			{
				Object.Destroy((Object)(object)val2, lifetime);
			}
		}

		internal static Sprite Icon(bool ash, string folder)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (ash && (Object)(object)ashIcon != (Object)null)
			{
				return ashIcon;
			}
			if (!ash && (Object)(object)iceIcon != (Object)null)
			{
				return iceIcon;
			}
			string text = Path.Combine(folder, "Assets", ash ? "ritual_cinzas_icon_v2.png" : "prisao_gelo_icon_v2.png");
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(text), false))
			{
				throw new InvalidDataException("Invalid skill icon: " + text);
			}
			((Object)val).name = (ash ? "RitualCinzas_IconV2" : "PrisaoGelo_IconV2");
			((Texture)val).filterMode = (FilterMode)2;
			Sprite result = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			if (ash)
			{
				ashIcon = result;
				ashTexture = val;
			}
			else
			{
				iceIcon = result;
				iceTexture = val;
			}
			return result;
		}

		internal static void Sound(Sounds sound, Vector3 point)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GlobalAudioManager audioManager = Global.AudioManager;
				if (audioManager != null)
				{
					audioManager.PlaySoundAtPosition(sound, point, 0f, 1f, 1f, 1f, 1f);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[GeloCinzas] AUDIO:" + ex.Message));
			}
		}

		internal static void Release()
		{
			if ((Object)(object)iceIcon != (Object)null)
			{
				Object.Destroy((Object)(object)iceIcon);
			}
			if ((Object)(object)ashIcon != (Object)null)
			{
				Object.Destroy((Object)(object)ashIcon);
			}
			if ((Object)(object)iceTexture != (Object)null)
			{
				Object.Destroy((Object)(object)iceTexture);
			}
			if ((Object)(object)ashTexture != (Object)null)
			{
				Object.Destroy((Object)(object)ashTexture);
			}
			if ((Object)(object)frost != (Object)null)
			{
				Object.Destroy((Object)(object)frost);
			}
			Mesh[] array = iceMeshes;
			foreach (Mesh val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			Array.Clear(iceMeshes, 0, iceMeshes.Length);
			iceIcon = (ashIcon = null);
			iceTexture = (ashTexture = null);
			frost = null;
		}
	}
	[BepInPlugin("codex.outward.gelo.cinzas", "Codex - Prisao de Gelo e Ritual das Cinzas", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.gelo.cinzas";

		public const int IceId = 9106980;

		public const int AshId = 9106990;

		internal static ManualLogSource Log;

		internal static readonly ExternalClip IceClip = new ExternalClip();

		internal static readonly ExternalClip AshClip = new ExternalClip();

		private readonly Dictionary<int, Skill> prefabs = new Dictionary<int, Skill>();

		private readonly HashSet<int> rejected = new HashSet<int>();

		private Harmony patches;

		private Sprite iceIcon;

		private Sprite ashIcon;

		private bool building;

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			iceIcon = FieldVisual.Icon(ash: false, directoryName);
			ashIcon = FieldVisual.Icon(ash: true, directoryName);
			patches = new Harmony("codex.outward.gelo.cinzas");
			patches.PatchAll(typeof(Plugin).Assembly);
			SL_Item.AddOnInstanceStartListener(9106980, (Action<Item>)Prepare);
			SL_Item.AddOnInstanceStartListener(9106990, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[GeloCinzas] 1.1.1;treinador;external Humanoid ice prison + ash ritual;native FireLinger;PENDING USER");
		}

		private void Build()
		{
			if (prefabs.Count == 2 || building)
			{
				return;
			}
			building = true;
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				IceClip.Build(directoryName, "codex_prisao_gelo", "CodexPrison_IceCall", "CodexPrisaoHumanoid_", "0351458F6940441994061B723D2E0B37F5D63B7FDEDAFCDCE7691533381F78C3");
				AshClip.Build(directoryName, "codex_ritual_cinzas", "CodexRitual_AshPlant", "CodexCinzasHumanoid_", "A20BCBC255B3CF6EE0A25ADAE0E3A8466D85EE6FBADB8D68F3C9DB9498EC7032");
				FieldVisual.Ensure();
				Create(9106980, "Prisao de Gelo", "Ergue um circulo de estalagmites de gelo ao redor de um inimigo a ate 15m por 5s. As paredes solidas restringem movimento, sem dano. 25 vigor, 35s de recarga.", 25, 35);
				Create(9106990, "Ritual das Cinzas", "Acende um circulo de brasas no chao a sua frente por 8s. Inimigos na area recebem 15 dano de fogo a cada segundo. 30 vigor, 45s de recarga.", 30, 45);
				Log.LogMessage((object)"[GeloCinzas] PRONTO:9106980/9106990;Human=True;ice5s;ash8s/15FirePerSecond");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[GeloCinzas] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Create(int id, string name, string description, int stamina, int cooldown)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			if (!prefabs.ContainsKey(id))
			{
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(id) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + id);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = id;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = name;
				((SL_Item)val2).Description = description;
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = stamina;
				((SL_Skill)val2).Cooldown = cooldown;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				Skill val3 = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)val3 == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed:" + id);
				}
				prefabs[id] = val3;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && (item.ItemID == 9106980 || item.ItemID == 9106990))
			{
				((Skill)item).StartVFX = null;
				Sprite val = ((item.ItemID == 9106980) ? iceIcon : ashIcon);
				CustomItemVisuals.SetSpriteLink(item, val, false);
				CustomItemVisuals.SetSpriteLink(item, val, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			FieldMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if (prefabs.Count == 2 && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								FieldMotion fieldMotion = ((Component)value).GetComponent<FieldMotion>();
								if ((Object)(object)fieldMotion == (Object)null)
								{
									try
									{
										fieldMotion = ((Component)value).gameObject.AddComponent<FieldMotion>();
										fieldMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)fieldMotion != (Object)null)
										{
											Object.Destroy((Object)(object)fieldMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[GeloCinzas] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = fieldMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			FieldMotion[] array = Object.FindObjectsOfType<FieldMotion>();
			foreach (FieldMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			FieldArea[] array2 = Object.FindObjectsOfType<FieldArea>();
			for (int i = 0; i < array2.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			}
			Harmony obj2 = patches;
			if (obj2 != null)
			{
				obj2.UnpatchAll("codex.outward.gelo.cinzas");
			}
			IceClip.Dispose();
			AshClip.Dispose();
			FieldVisual.Release();
		}
	}
	internal static class BundleHashes
	{
		internal const string Ice = "0351458F6940441994061B723D2E0B37F5D63B7FDEDAFCDCE7691533381F78C3";

		internal const string Ash = "A20BCBC255B3CF6EE0A25ADAE0E3A8466D85EE6FBADB8D68F3C9DB9498EC7032";
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (FieldMotion.Our(((Item)__instance).ItemID))
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<FieldMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			FieldMotion component = ((Component)__instance).GetComponent<FieldMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance, bool _wasCancelled)
		{
			if (FieldMotion.Our(((Item)__instance).ItemID))
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				FieldMotion fieldMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<FieldMotion>() : null);
				if (_wasCancelled)
				{
					fieldMotion?.Cancel("native cancelled");
				}
				else
				{
					fieldMotion?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<FieldMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				FieldMotion fieldMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<FieldMotion>() : null);
				if (FieldMotion.Our(((Item)__instance).ItemID))
				{
					__result = fieldMotion?.CanBegin(((Item)__instance).ItemID) ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && fieldMotion != null && fieldMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			FieldMotion component = ((Component)__instance).GetComponent<FieldMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}

BepInEx/plugins/Codex_Habilidades_Sons/CodexHabilidadesSons.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHabilidadesSons
{
	[BepInPlugin("codex.outward.habilidades.sons", "Codex - Sons das Habilidades", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.habilidades.sons";

		private Harmony harmony;

		private readonly HashSet<string> warned = new HashSet<string>();

		private static Plugin instance;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			instance = this;
			harmony = new Harmony("codex.outward.habilidades.sons");
			Hook("CodexComboRubro.ComboAttack", "Release", "ComboRelease");
			Hook("CodexInvestidaCarmesim.DashAttack", "Release", "DashRelease");
			Hook("CodexSaltoTempestade.TempestAttack", "Release", "TempestRelease");
			Hook("CodexLancaTempestade.SpearAttack", "Release", "SpearRelease");
			Hook("CodexLancaTempestade.SpearVisual", "Burst", "SpearImpact");
			Hook("CodexUivoLoucura.UivoMotion", "Begin", "UivoBegin");
			Hook("CodexUivoLoucura.UivoBuff", "Apply", "UivoBuffApplied");
		}

		private void Hook(string typeName, string methodName, string callback)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			try
			{
				Type type = AccessTools.TypeByName(typeName);
				MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, methodName, (Type[])null, (Type[])null));
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), callback, (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("[HabilidadesSons] Sem alvo: " + typeName + "." + methodName));
					return;
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogMessage((object)("[HabilidadesSons] Audio ligado: " + typeName + "." + methodName));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[HabilidadesSons] Falha ao ligar " + typeName + "." + methodName + ": " + ex));
			}
		}

		private static void ComboRelease(object[] __args)
		{
			object obj = __args[1];
			Character owner = (Character)((obj is Character) ? obj : null);
			Play((Sounds)13182, owner, "combo");
			Play((Sounds)12963, owner, "combo-feixe", 0.48f);
		}

		private static void DashRelease(object[] __args)
		{
			object obj = __args[1];
			Character owner = (Character)((obj is Character) ? obj : null);
			Play((Sounds)13182, owner, "resvaldo");
			Play((Sounds)12976, owner, "resvaldo-feixe", 0.6f);
		}

		private static void TempestRelease(object[] __args)
		{
			object obj = __args[1];
			Character owner = (Character)((obj is Character) ? obj : null);
			Play((Sounds)13150, owner, "salto-pouso");
			Play((Sounds)12970, owner, "salto-raio", 0.8f);
		}

		private static void SpearRelease(object[] __args)
		{
			object obj = __args[0];
			Play((Sounds)12973, (Character)((obj is Character) ? obj : null), "lanca-arremesso");
		}

		private static void SpearImpact(object[] __args)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (__args.Length != 0 && __args[0] is Vector3 point)
			{
				Play((Sounds)12971, point, "lanca-impacto");
			}
		}

		private static void UivoBegin(object[] __args, bool __result)
		{
			if (!__result)
			{
				return;
			}
			object obj = __args[0];
			Skill val = (Skill)((obj is Skill) ? obj : null);
			Character val2 = ((val != null) ? ((EffectSynchronizer)val).OwnerCharacter : null);
			Play((Sounds)13240, val2, "uivo-inicio", 0.6f);
			if ((Object)(object)val2 != (Object)null && val2.IsLocalPlayer)
			{
				Plugin plugin = instance;
				if (plugin != null)
				{
					((MonoBehaviour)plugin).StartCoroutine(UivoCry(val2, val));
				}
			}
		}

		private static IEnumerator UivoCry(Character owner, Skill skill)
		{
			yield return (object)new WaitForSeconds(0.45f);
			if ((Object)(object)owner != (Object)null && owner.Alive && (Object)(object)skill != (Object)null && (Object)(object)owner.CastReceiver == (Object)(object)((Component)skill).gameObject)
			{
				Play((Sounds)50430, owner, "uivo-grito");
			}
		}

		private static void UivoBuffApplied(object[] __args, bool __result)
		{
			if (__result)
			{
				object obj = __args[0];
				Play((Sounds)13210, (Character)((obj is Character) ? obj : null), "uivo-buff", 0.9f);
			}
		}

		private static void Play(Sounds sound, Character owner, string key, float volume = 1f)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)owner != (Object)null && owner.IsLocalPlayer)
			{
				Play(sound, ((Component)owner).transform, key, volume);
			}
		}

		private static void Play(Sounds sound, Vector3 point, string key, float volume = 1f)
		{
			//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)
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			NetworkLevelLoader obj = NetworkLevelLoader.Instance;
			if (obj != null && obj.IsGameplayPaused)
			{
				return;
			}
			try
			{
				GlobalAudioManager audioManager = Global.AudioManager;
				if (audioManager != null)
				{
					audioManager.PlaySoundAtPosition(sound, point, 0f, volume, volume, 1f, 1f);
				}
			}
			catch (Exception ex)
			{
				instance.Warn(key, ex);
			}
		}

		private static void Play(Sounds sound, Transform anchor, string key, float volume = 1f)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)instance == (Object)null || (Object)(object)anchor == (Object)null)
			{
				return;
			}
			NetworkLevelLoader obj = NetworkLevelLoader.Instance;
			if (obj != null && obj.IsGameplayPaused)
			{
				return;
			}
			try
			{
				GlobalAudioManager audioManager = Global.AudioManager;
				if (audioManager != null)
				{
					audioManager.PlaySoundAtPosition(sound, anchor, 0f, volume, volume, 1f, 1f);
				}
			}
			catch (Exception ex)
			{
				instance.Warn(key, ex);
			}
		}

		private void Warn(string key, Exception ex)
		{
			if (warned.Add(key))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[HabilidadesSons] " + key + ": " + ex.Message));
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchAll("codex.outward.habilidades.sons");
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}
	}
}

BepInEx/plugins/Codex_Investida_Carmesim/CodexInvestidaCarmesim.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexCombat;
using CodexCorteCarmesim;
using CodexHumanoidExtras;
using CodexSkillIcons;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexCorteCarmesim
{
	public static class CarmVisual
	{
		private static Material _material;

		private static Texture2D _sprite;

		private static Texture2D _icon;

		private static Mesh _crescent;

		private static Sprite _iconSprite;

		private static void Ensure()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_015b: 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_0346: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_material != (Object)null)
			{
				return;
			}
			_sprite = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				name = "Carm_GotaSuave"
			};
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					Vector2 val = new Vector2(((float)j - 63.5f) / 63.5f, ((float)i - 63.5f) / 63.5f);
					float magnitude = ((Vector2)(ref val)).magnitude;
					array[i * 128 + j] = new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - magnitude), 2f));
				}
			}
			_sprite.SetPixels(array);
			_sprite.Apply(false, true);
			((Texture)_sprite).wrapMode = (TextureWrapMode)1;
			Shader obj = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("Shader de particulas ausente");
			}
			_material = new Material(obj)
			{
				name = "Carm_VFX_Compartilhado",
				mainTexture = (Texture)(object)_sprite
			};
			if (_material.HasProperty("_TintColor"))
			{
				_material.SetColor("_TintColor", Color.white);
			}
			Vector3[] array2 = (Vector3[])(object)new Vector3[130];
			Vector2[] array3 = (Vector2[])(object)new Vector2[array2.Length];
			Color[] array4 = (Color[])(object)new Color[array2.Length];
			int[] array5 = new int[384];
			for (int k = 0; k <= 64; k++)
			{
				float num = (float)k / 64f;
				float num2 = Mathf.Lerp(-128f, 128f, num) * ((float)Math.PI / 180f);
				float num3 = 0.12f * Mathf.Pow(Mathf.Sin(num * (float)Math.PI), 0.6f);
				float num4 = 0.025f * Mathf.Sin((float)k * 1.9f) * Mathf.Sin(num * (float)Math.PI);
				for (int l = 0; l < 2; l++)
				{
					float num5 = 1f + ((l == 0) ? (0f - num3) : num3) + num4;
					int num6 = k * 2 + l;
					array2[num6] = new Vector3((Mathf.Cos(num2) * num5 * 0.9f - 0.25f) * 2f, Mathf.Sin(num2) * num5 * 0.85f, 0f);
					array3[num6] = new Vector2(0.5f, (l == 0) ? 0.32f : 0.68f);
					array4[num6] = ((l == 0) ? new Color(0.06f, 0.62f, 1f, 1f) : new Color(0.015f, 0.1f, 0.55f, 0.65f));
				}
				if (k < 64)
				{
					int num7 = k * 2;
					int num8 = k * 6;
					array5[num8] = num7;
					array5[num8 + 1] = num7 + 1;
					array5[num8 + 2] = num7 + 2;
					array5[num8 + 3] = num7 + 1;
					array5[num8 + 4] = num7 + 3;
					array5[num8 + 5] = num7 + 2;
				}
			}
			_crescent = new Mesh
			{
				name = "Carm_Arco_128tri"
			};
			_crescent.vertices = array2;
			_crescent.uv = array3;
			_crescent.colors = array4;
			_crescent.triangles = array5;
			_crescent.RecalculateBounds();
		}

		public static void Wave(Transform parent)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			for (int i = 0; i < 3; i++)
			{
				GameObject val = new GameObject("Arco_Camada_" + i);
				val.transform.SetParent(parent, false);
				val.transform.localScale = Vector3.one * (1f + (float)i * 0.13f);
				val.transform.localPosition = new Vector3(0f, 0f, -0.035f * (float)i);
				val.AddComponent<MeshFilter>().sharedMesh = _crescent;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = _material;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)obj).receiveShadows = false;
			}
			Particles(parent, burst: false);
		}

		public static void Burst(Vector3 point)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Carm_Impacto");
			val.transform.position = point;
			Particles(val.transform, burst: true);
			Object.Destroy((Object)val, 1.1f);
		}

		private static void Particles(Transform parent, bool burst)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(burst ? "Gotas_Impacto" : "Gotas_Rastro");
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = !burst;
			((MainModule)(ref main)).duration = 0.6f;
			((MainModule)(ref main)).maxParticles = 80;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.22f, 0.55f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.04f, 0.17f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(burst ? 1.2f : 0.2f, burst ? 4f : 0.8f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.06f, 0.5f, 1f, 0.8f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(burst ? 0.25f : 0.02f);
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit((float)((!burst) ? 72 : 0));
			if (burst)
			{
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)28)
				});
			}
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = (burst ? 0.12f : 0.52f);
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(0.15f, 0.7f, 1f), 0f),
				new GradientColorKey(new Color(0.015f, 0.06f, 0.3f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.85f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = _material;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			val2.Play();
		}

		public static Sprite CreateIcon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			if ((Object)(object)_iconSprite != (Object)null)
			{
				return _iconSprite;
			}
			_icon = new Texture2D(256, 256, (TextureFormat)4, false)
			{
				name = "CorteCarmesim_Icon"
			};
			Color[] array = (Color[])(object)new Color[65536];
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num = ((float)j - 127.5f) / 127.5f;
					float num2 = ((float)i - 127.5f) / 127.5f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Atan2(num2, num);
					float num5 = Mathf.Exp(0f - Mathf.Pow((num3 - 0.63f) * 28f, 2f)) * Mathf.Clamp01(1f - Mathf.Abs(num4) / 2.35f);
					float num6 = Mathf.Exp(0f - Mathf.Pow((num3 - 0.63f) * 9f, 2f)) * Mathf.Clamp01(1f - Mathf.Abs(num4) / 2.7f);
					float num7 = Mathf.Exp(0f - Mathf.Pow((num2 - num) * 45f, 2f)) * (float)((num3 < 0.72f) ? 1 : 0);
					float num8 = Mathf.Clamp01((1f - num3) * 14f);
					array[i * 256 + j] = new Color(0.06f + num5 * 0.94f + num6 * 0.35f + num7 * 0.65f, 0.018f + num7 * 0.38f + num5 * 0.07f, 0.03f + num7 * 0.4f + num5 * 0.15f, num8);
				}
			}
			_icon.SetPixels(array);
			_icon.Apply(false, true);
			_iconSprite = Sprite.Create(_icon, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
			Object.DontDestroyOnLoad((Object)(object)_icon);
			Object.DontDestroyOnLoad((Object)(object)_iconSprite);
			return _iconSprite;
		}

		public static void Release()
		{
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
			if ((Object)(object)_sprite != (Object)null)
			{
				Object.Destroy((Object)(object)_sprite);
			}
			if ((Object)(object)_crescent != (Object)null)
			{
				Object.Destroy((Object)(object)_crescent);
			}
			if ((Object)(object)_icon != (Object)null)
			{
				Object.Destroy((Object)(object)_icon);
			}
			if ((Object)(object)_iconSprite != (Object)null)
			{
				Object.Destroy((Object)(object)_iconSprite);
			}
			_material = null;
			_sprite = null;
			_crescent = null;
			_icon = null;
			_iconSprite = null;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexSkillIcons
{
	internal static class SkillIcon
	{
		private static readonly HashSet<Sprite> owned = new HashSet<Sprite>();

		internal static Sprite Load(string folder, Func<Sprite> fallback, Action<string> warning)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = null;
			Sprite val2 = null;
			try
			{
				val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					name = "Codex_SkillIcon_Painted",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)2
				};
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, "UI", "skill-icon.png")), false) || ((Texture)val).width != 512 || ((Texture)val).height != 512)
				{
					throw new InvalidDataException("Expected512x512 skill-icon.png");
				}
				val.Apply(true, true);
				val2 = Sprite.Create(val, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidDataException("Icon Sprite unavailable");
				}
				owned.Add(val2);
				return val2;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				warning?.Invoke("ICON_FALLBACK:" + ex.Message);
				return fallback();
			}
		}

		internal static void Release(Sprite sprite)
		{
			if (!((Object)(object)sprite == (Object)null) && owned.Remove(sprite))
			{
				Object.Destroy((Object)(object)sprite.texture);
				Object.Destroy((Object)(object)sprite);
			}
		}
	}
}
namespace CodexInvestidaCarmesim
{
	internal static class DashAttack
	{
		internal const float ContactDamage = 100f;

		internal const float ContactImpact = 30f;

		internal const float WaveDamage = 100f;

		internal const float WaveImpact = 15f;

		internal const float Reach = 2.8f;

		internal const float Range = 8f;

		internal const float Speed = 22f;

		internal const float Radius = 0.48f;

		internal static Character Victim(Character owner, Collider collider)
		{
			Hitbox componentInParent = ((Component)collider).GetComponentInParent<Hitbox>();
			Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val != (Object)(object)owner) || !val.Alive || val.IsLocalPlayer || !((Object)(object)owner.TargetingSystem != (Object)null) || !owner.TargetingSystem.IsTargetable(val))
			{
				return null;
			}
			return val;
		}

		internal static void Release(DashMotion source, Character owner, Vector3 direction)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Character> hashSet = new HashSet<Character>();
			Vector3 centerPosition = owner.CenterPosition;
			Collider[] array = Physics.OverlapSphere(centerPosition, 2.8f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			Vector3 val3 = default(Vector3);
			foreach (Collider collider in array)
			{
				Character val = Victim(owner, collider);
				if (!((Object)(object)val == (Object)null) && !hashSet.Contains(val))
				{
					Vector3 val2 = val.CenterPosition - centerPosition;
					((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
					if (!(Mathf.Abs(val2.y) > 1.7f) && !(Vector3.Angle(direction, val3) > 75f) && !Physics.Linecast(centerPosition, val.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
					{
						hashSet.Add(val);
						bool flag = PhysicalContactHit.Apply((MonoBehaviour)(object)source, owner, val, 100f, ((Vector3)(ref val2)).normalized, 30f, blockable: true);
						DashVisual.Burst(val.CenterPosition);
						Plugin.Log.LogMessage((object)("[InvestidaCarmesim] CONTACT:" + 1 + ";" + val.Name + (flag ? ";BLOCKED" : "")));
					}
				}
			}
			GameObject val4 = new GameObject("InvestidaCarmesim_Feixe_" + 1);
			val4.transform.position = centerPosition;
			val4.transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
			val4.AddComponent<DashWave>().Bind(owner, hashSet, direction);
			Plugin.Log.LogMessage((object)("[InvestidaCarmesim] RELEASE:" + 1 + "/1;straightBlade;diagonal=" + DashRibbon.Angle(0) + ";range8m;single-strike dedup"));
		}
	}
	public sealed class DashWave : MonoBehaviour
	{
		private Character owner;

		private HashSet<Character> victims;

		private Vector3 direction;

		private float distance;

		private float age;

		private int mask;

		private int hit;

		internal void Bind(Character value, HashSet<Character> contacts, Vector3 facing)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			owner = value;
			victims = new HashSet<Character>(contacts);
			direction = facing;
			hit = 0;
			mask = Global.GeneralEnvironmentMask | LayerMask.GetMask(new string[1] { "Hitbox" });
			DashVisual.Blade(((Component)this).transform, 0);
		}

		private void Update()
		{
			//IL_00a7: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				float deltaTime = Time.deltaTime;
				age += deltaTime;
				if (age > 1.5f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				float num = Mathf.Min(22f * deltaTime, 8f - distance);
				if (num <= 0f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 0.48f, mask, (QueryTriggerInteraction)2);
				Collider[] array2 = array;
				foreach (Collider collider in array2)
				{
					if (Wall(collider))
					{
						Impact(((Component)this).transform.position);
						return;
					}
				}
				array2 = array;
				foreach (Collider collider2 in array2)
				{
					Damage(collider2);
				}
				RaycastHit[] array3 = Physics.SphereCastAll(((Component)this).transform.position, 0.48f, direction, num, mask, (QueryTriggerInteraction)2);
				Array.Sort(array3, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
				RaycastHit[] array4 = array3;
				for (int i = 0; i < array4.Length; i++)
				{
					RaycastHit val = array4[i];
					if (Wall(((RaycastHit)(ref val)).collider))
					{
						Impact(((RaycastHit)(ref val)).point);
						return;
					}
					Damage(((RaycastHit)(ref val)).collider);
				}
				Transform transform = ((Component)this).transform;
				transform.position += direction * num;
				distance += num;
				if (distance >= 7.999f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private bool Wall(Collider collider)
		{
			if (!collider.isTrigger && (Global.GeneralEnvironmentMask & (1 << ((Component)collider).gameObject.layer)) != 0)
			{
				return (Object)(object)((Component)collider).GetComponentInParent<Character>() == (Object)null;
			}
			return false;
		}

		private void Damage(Collider collider)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Character val = DashAttack.Victim(owner, collider);
			if (!((Object)(object)val == (Object)null) && victims.Add(val))
			{
				val.ReceiveHit((Object)null, new DamageList((Types)2, 100f), direction, val.CenterPosition, 45f, 1f, owner, 15f, true);
				DashVisual.Burst(val.CenterPosition);
				Plugin.Log.LogMessage((object)("[InvestidaCarmesim] WAVE:" + (hit + 1) + ";" + val.Name + ";100Decay/15impact"));
			}
		}

		private void Impact(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			DashVisual.Burst(position);
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	internal static class DashClip
	{
		internal const string Prefix = "InvestidaCarmesimHumanoid_";

		internal const float Duration = 1.5666667f;

		internal const string Hash = "CB589C261DCB44405155FDFC9E10B3BADF461FDB2528CA189D566F27FC000ABD";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_investida_carmesim");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "CB589C261DCB44405155FDFC9E10B3BADF461FDB2528CA189D566F27FC000ABD")
					{
						throw new InvalidDataException("Compiled combo SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled combo bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexInvestida_SwordDash");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 1.5666667f) > 0.001f)
				{
					throw new InvalidDataException("Expected official external Humanoid Sword_Dash");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "InvestidaCarmesimHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	public sealed class DashMotion : MonoBehaviour
	{
		private Character player;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private DashTimeline clock;

		private bool nativeCast;

		private bool movementStopped;

		private float normalized;

		private float moved;

		private Vector3 direction;

		private TrailRenderer trail;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (DashClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding && (Object)(object)player.CharacterController != (Object)null && ((Collider)player.CharacterController).enabled)
				{
					return (Object)(object)player.Animator.avatar == (Object)(object)avatar;
				}
				return false;
			}
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				DashClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (((Item)value).ItemID != 9106920 || !CanBegin)
			{
				return false;
			}
			try
			{
				lease.Acquire(DashClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new DashTimeline();
				nativeCast = (movementStopped = false);
				normalized = (moved = 0f);
				Vector3 val = Vector3.ProjectOnPlane(((Component)player).transform.forward, Vector3.up);
				direction = ((Vector3)(ref val)).normalized;
				Plugin.Log.LogMessage((object)("[InvestidaCarmesim] CAST;Sword_Dash;nativeAvatar=" + ((Object)avatar).name + ";24vigor/8s"));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && !((Object)(object)value != (Object)(object)skill) && !tail.NativeEnded)
			{
				tail.EndNative();
				Plugin.Log.LogMessage((object)"[InvestidaCarmesim] NATIVEEND;retain override through blend-out");
			}
		}

		private void LateUpdate()
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
				return;
			}
			if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
				return;
			}
			if (instance.IsGameplayPaused)
			{
				if ((Object)(object)trail != (Object)null)
				{
					trail.emitting = false;
				}
				return;
			}
			bool flag = false;
			bool observed = tail.Observed;
			for (int i = 0; i < player.Animator.layerCount; i++)
			{
				bool num = flag;
				AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
				AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
				flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
				if (player.Animator.IsInTransition(i))
				{
					bool num2 = flag;
					AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
					val = player.Animator.GetNextAnimatorStateInfo(i);
					flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
				}
			}
			tail.Sample(Time.deltaTime, flag);
			if (!observed && tail.Observed)
			{
				Plugin.Log.LogMessage((object)"[InvestidaCarmesim] EXTERNALACTIVE;Human=True;AvatarUNCHANGED");
			}
			if (flag)
			{
				try
				{
					clock.Observe(normalized);
					if (clock.Started && !nativeCast)
					{
						if (!OwnCast)
						{
							Fail("Native receiver lost before cost");
							return;
						}
						NativeInvocation = true;
						nativeCast = true;
						((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
						NativeInvocation = false;
						if (!Active || !OwnCast)
						{
							return;
						}
						trail = DashVisual.DashTrail(((Component)player).transform);
					}
					if (clock.Moving && nativeCast && !movementStopped)
					{
						float requested = DashTimeline.Step(clock.DesiredDistance, moved, Time.deltaTime);
						moved += DashMovement.Advance(player, direction, requested, out movementStopped);
						if (movementStopped)
						{
							Plugin.Log.LogMessage((object)("[InvestidaCarmesim] DASHSTOP;wall/ledge/slope;travel=" + moved));
						}
					}
					if ((Object)(object)trail != (Object)null)
					{
						trail.emitting = clock.Moving && !movementStopped;
					}
					if (clock.TryStrike() && nativeCast)
					{
						DashAttack.Release(this, player, direction);
					}
				}
				catch (Exception ex)
				{
					Fail("RELEASEFAILED:" + ex);
					return;
				}
				finally
				{
					NativeInvocation = false;
				}
			}
			else if ((Object)(object)trail != (Object)null)
			{
				trail.emitting = false;
			}
			if (tail.CanRestore)
			{
				Cancel("native blend-out complete");
			}
			else if (tail.TimedOut(1.5666667f))
			{
				Fail("External clip/transition timeout");
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("InvestidaCarmesimHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[InvestidaCarmesim] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			clock?.Cancel();
			bool active = Active;
			skill = null;
			tail = null;
			clock = null;
			nativeCast = false;
			if ((Object)(object)trail != (Object)null)
			{
				trail.emitting = false;
				((Component)trail).transform.SetParent((Transform)null, true);
				Object.Destroy((Object)(object)((Component)trail).gameObject, 0.2f);
				trail = null;
			}
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[InvestidaCarmesim] RESTORED;reason=" + reason + ";travel=" + moved));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[InvestidaCarmesim] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal static class DashMovement
	{
		internal static float Advance(Character player, Vector3 direction, float requested, out bool stopped)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			stopped = false;
			CharacterController characterController = player.CharacterController;
			if ((Object)(object)characterController == (Object)null || !((Collider)characterController).enabled || player.Falling || player.Sliding)
			{
				stopped = true;
				return 0f;
			}
			float num = 0f;
			int num2 = 0;
			RaycastHit val2 = default(RaycastHit);
			Vector3 val3 = default(Vector3);
			Vector3 val4 = default(Vector3);
			while (requested > 0.001f && num2++ < 10)
			{
				float num3 = Mathf.Min(requested, 0.2f);
				Vector3 val = direction * num3;
				Bounds bounds = ((Collider)characterController).bounds;
				float num4 = Mathf.Max(0.05f, characterController.radius * 0.9f * Mathf.Abs(((Component)player).transform.lossyScale.x));
				if (!Physics.SphereCast(new Vector3(((Bounds)(ref bounds)).center.x + val.x, ((Bounds)(ref bounds)).min.y + 0.65f, ((Bounds)(ref bounds)).center.z + val.z), num4 * 0.6f, Vector3.down, ref val2, 1.15f + num4, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1) || ((RaycastHit)(ref val2)).point.y < ((Bounds)(ref bounds)).min.y - 0.45f || ((RaycastHit)(ref val2)).point.y > ((Bounds)(ref bounds)).min.y + characterController.stepOffset + 0.08f || Vector3.Angle(((RaycastHit)(ref val2)).normal, Vector3.up) > characterController.slopeLimit)
				{
					stopped = true;
					break;
				}
				((Vector3)(ref val3))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y + num4, ((Bounds)(ref bounds)).center.z);
				((Vector3)(ref val4))..ctor(((Bounds)(ref bounds)).center.x, Mathf.Max(val3.y, ((Bounds)(ref bounds)).max.y - num4), ((Bounds)(ref bounds)).center.z);
				RaycastHit[] array = Physics.CapsuleCastAll(val3, val4, num4, direction, num3 + 0.04f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				for (int i = 0; i < array.Length; i++)
				{
					RaycastHit val5 = array[i];
					if (!((Component)((RaycastHit)(ref val5)).collider).transform.IsChildOf(((Component)player).transform) && !(((RaycastHit)(ref val5)).normal.y > 0.5f))
					{
						num3 = Mathf.Min(num3, Mathf.Max(0f, ((RaycastHit)(ref val5)).distance - 0.04f));
						stopped = true;
					}
				}
				if (num3 <= 0.001f)
				{
					break;
				}
				Vector3 position = ((Component)player).transform.position;
				characterController.Move(direction * num3);
				float num5 = Mathf.Max(0f, Vector3.Dot(((Component)player).transform.position - position, direction));
				num += num5;
				requested -= num3;
				if (num5 < num3 * 0.5f)
				{
					stopped = true;
					break;
				}
				if (stopped)
				{
					break;
				}
			}
			return num;
		}
	}
	internal static class DashRibbon
	{
		internal readonly struct Vertex
		{
			internal readonly float X;

			internal readonly float Y;

			internal readonly float U;

			internal readonly float V;

			internal readonly float Alpha;

			internal Vertex(float x, float y, float u, float v, float alpha)
			{
				X = x;
				Y = y;
				U = u;
				V = v;
				Alpha = alpha;
			}
		}

		internal const int Segments = 28;

		internal const int Rows = 5;

		internal const float HalfLength = 2.7f;

		internal const float HalfWidth = 0.075f;

		internal static float Angle(int strike)
		{
			if (strike < 0 || strike > 3)
			{
				throw new ArgumentOutOfRangeException("strike");
			}
			return (strike % 2 == 0) ? 32 : (-32);
		}

		internal static Vertex[] Vertices()
		{
			Vertex[] array = new Vertex[145];
			for (int i = 0; i <= 28; i++)
			{
				float num = (float)i / 28f;
				float num2 = (float)Math.Pow(Math.Max(0.0, Math.Sin((double)num * Math.PI)), 0.55);
				float num3 = 0.075f * num2 * (1f + 0.06f * (float)Math.Sin(num * 29f));
				for (int j = 0; j < 5; j++)
				{
					float num4 = (float)j / 4f;
					float num5 = num4 * 2f - 1f;
					array[i * 5 + j] = new Vertex((num * 2f - 1f) * 2.7f, num5 * num3, num, num4, num2 * (float)Math.Pow(1f - Math.Abs(num5), 0.65));
				}
			}
			return array;
		}

		internal static int[] Triangles()
		{
			int[] array = new int[672];
			int num = 0;
			for (int i = 0; i < 28; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					int num2 = i * 5 + j;
					int num3 = num2 + 5;
					int num4 = num3 + 1;
					int num5 = num2 + 1;
					array[num++] = num2;
					array[num++] = num3;
					array[num++] = num5;
					array[num++] = num5;
					array[num++] = num3;
					array[num++] = num4;
				}
			}
			return array;
		}
	}
	internal static class DashTexture
	{
		internal readonly struct Pixel
		{
			internal readonly float R;

			internal readonly float G;

			internal readonly float B;

			internal readonly float A;

			internal Pixel(float r, float g, float b, float a)
			{
				R = r;
				G = g;
				B = b;
				A = a;
			}
		}

		internal const int Width = 2048;

		internal const int Height = 512;

		private static float Clamp(float value)
		{
			return Math.Max(0f, Math.Min(1f, value));
		}

		internal static Pixel Sample(int x, int y)
		{
			if (x < 0 || x >= 2048 || y < 0 || y >= 512)
			{
				throw new ArgumentOutOfRangeException();
			}
			float num = (float)x / 2047f;
			float num2 = ((float)y - 255.5f) / 255.5f;
			float num3 = Clamp(1f - Math.Abs(num2));
			float num4 = 0.065f * (float)Math.Sin(num * 15f) + 0.025f * (float)Math.Sin(num * 41f);
			float num5 = (float)Math.Sin((double)((num2 - num4) * 18f + num * 7f) + 0.7 * Math.Sin(num * 25f));
			float num6 = (float)Math.Pow(Clamp((float)Math.Sin((num2 - num4) * 54f - num * 11f)), 8.0);
			float num7 = (float)Math.Pow(Clamp(1f - Math.Abs((float)Math.Sin((double)(num * 59f + num2 * 5f) + 0.45 * Math.Sin(num * 31f))) / 0.22f), 2.0);
			float num8 = Clamp((0.72f + 0.13f * num5 + 0.2f * num6) * (1f - num7 * (0.55f + 0.18f * Math.Abs(num2))));
			float a = (float)Math.Pow(num3, 0.7) * num8;
			return new Pixel(0.04f + 0.18f * num3, 0.2f + 0.55f * num3, 0.6f + 0.4f * num3, a);
		}
	}
	internal sealed class DashTimeline
	{
		internal const float StartAt = 0.04255319f;

		internal const float EndAt = 0.23404256f;

		internal const float StrikeAt = 0.21276596f;

		internal const float Distance = 3f;

		internal const float MaxSpeed = 18f;

		private float progress;

		private bool released;

		private bool cancelled;

		internal bool Started
		{
			get
			{
				if (!cancelled)
				{
					return progress >= 0.04255319f;
				}
				return false;
			}
		}

		internal bool Moving
		{
			get
			{
				if (Started)
				{
					return progress <= 0.23404256f;
				}
				return false;
			}
		}

		internal float DesiredDistance => TravelAt(progress);

		internal void Observe(float value)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, value);
			}
		}

		internal bool TryStrike()
		{
			if (cancelled || released || progress < 0.21276596f)
			{
				return false;
			}
			released = true;
			return true;
		}

		internal void Cancel()
		{
			cancelled = true;
		}

		internal static float TravelAt(float value)
		{
			float num = Math.Max(0f, Math.Min(1f, (value - 0.04255319f) / 0.19148937f));
			return 3f * num * num * (3f - 2f * num);
		}

		internal static float Step(float desired, float moved, float dt)
		{
			if (float.IsNaN(dt) || float.IsInfinity(dt) || dt <= 0f)
			{
				return 0f;
			}
			return Math.Max(0f, Math.Min(desired - moved, 18f * Math.Min(dt, 0.1f)));
		}
	}
	internal static class DashVisual
	{
		private static Mesh ribbon;

		private static Material bladeMaterial;

		private static Material sparkMaterial;

		private static Texture2D bladeTexture;

		private static Texture2D sparkTexture;

		internal static Func<bool> Paused;

		internal static void Ensure()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01be: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Expected O, but got Unknown
			if ((Object)(object)ribbon != (Object)null)
			{
				return;
			}
			Shader val = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Red blade particle shader unavailable");
			}
			if (SystemInfo.maxTextureSize < 2048)
			{
				throw new InvalidOperationException("2K red blade texture exceeds GPU texture limit:" + SystemInfo.maxTextureSize);
			}
			bladeTexture = new Texture2D(2048, 512, (TextureFormat)4, true)
			{
				name = "Rubro_Estrias_Fissuras_2K",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)2,
				anisoLevel = 2
			};
			Color32[] array = (Color32[])(object)new Color32[1048576];
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 2048; j++)
				{
					DashTexture.Pixel pixel = DashTexture.Sample(j, i);
					array[i * 2048 + j] = Color32.op_Implicit(new Color(pixel.R, pixel.G, pixel.B, pixel.A));
				}
			}
			bladeTexture.SetPixels32(array);
			bladeTexture.Apply(true, true);
			sparkTexture = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "Rubro_Faisca_Suave",
				wrapMode = (TextureWrapMode)1
			};
			array = (Color32[])(object)new Color32[4096];
			for (int k = 0; k < 64; k++)
			{
				for (int l = 0; l < 64; l++)
				{
					Vector2 val2 = new Vector2(((float)l - 31.5f) / 31.5f, ((float)k - 31.5f) / 31.5f);
					float magnitude = ((Vector2)(ref val2)).magnitude;
					array[k * 64 + l] = Color32.op_Implicit(new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - magnitude), 2f)));
				}
			}
			sparkTexture.SetPixels32(array);
			sparkTexture.Apply(false, true);
			bladeMaterial = Material(val, (Texture)(object)bladeTexture, "Rubro_Lamina_Compartilhada");
			sparkMaterial = Material(val, (Texture)(object)sparkTexture, "Rubro_Faiscas_Compartilhadas");
			DashRibbon.Vertex[] array2 = DashRibbon.Vertices();
			Vector3[] array3 = (Vector3[])(object)new Vector3[array2.Length];
			Vector2[] array4 = (Vector2[])(object)new Vector2[array2.Length];
			Color[] array5 = (Color[])(object)new Color[array2.Length];
			for (int m = 0; m < array2.Length; m++)
			{
				DashRibbon.Vertex vertex = array2[m];
				array3[m] = new Vector3(vertex.X, vertex.Y, 0f);
				array4[m] = new Vector2(vertex.U, vertex.V);
				float num = 1f - Mathf.Abs(vertex.V * 2f - 1f);
				array5[m] = Color.Lerp(new Color(0.015f, 0.2f, 0.75f, vertex.Alpha), new Color(0.25f, 0.9f, 1.12f, vertex.Alpha), num * num);
			}
			ribbon = new Mesh
			{
				name = "Rubro_Lamina_Reta_Afilada"
			};
			ribbon.vertices = array3;
			ribbon.uv = array4;
			ribbon.colors = array5;
			ribbon.triangles = DashRibbon.Triangles();
			ribbon.RecalculateBounds();
		}

		private static Material Material(Shader shader, Texture texture, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(shader)
			{
				name = name,
				mainTexture = texture
			};
			if (val.HasProperty("_TintColor"))
			{
				val.SetColor("_TintColor", Color.white);
			}
			return val;
		}

		private static Transform Layer(Transform parent, string name, Vector3 scale, float depth, float brightness)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localScale = scale;
			val.transform.localPosition = new Vector3(0f, 0f, depth);
			val.AddComponent<MeshFilter>().sharedMesh = ribbon;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = bladeMaterial;
			MaterialPropertyBlock val2 = new MaterialPropertyBlock();
			val2.SetColor("_TintColor", new Color(brightness, brightness, brightness, 1f));
			val2.SetColor("_Color", new Color(brightness, brightness, brightness, 1f));
			((Renderer)obj).SetPropertyBlock(val2);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return val.transform;
		}

		internal static void Blade(Transform parent, int strike)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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)
			Ensure();
			GameObject val = new GameObject("Lamina_Rubra_Reta");
			val.transform.SetParent(parent, false);
			val.transform.localRotation = Quaternion.Euler(0f, 0f, DashRibbon.Angle(strike));
			Transform halo = Layer(val.transform, "Borda_Rubra", new Vector3(1.04f, 3.4f, 1f), -0.02f, 0.23f);
			Layer(val.transform, "Nucleo_Estriado", Vector3.one, 0.02f, 0.62f);
			ParticleSystem particles = Particles(val.transform, burst: false);
			GameObject val2 = new GameObject("Rastro_Curto");
			val2.transform.SetParent(parent, false);
			TrailRenderer val3 = val2.AddComponent<TrailRenderer>();
			((Renderer)val3).sharedMaterial = sparkMaterial;
			val3.time = 0.12f;
			val3.minVertexDistance = 0.08f;
			val3.widthMultiplier = 0.11f;
			val3.numCapVertices = 2;
			val3.widthCurve = AnimationCurve.Linear(0f, 1f, 1f, 0f);
			val3.colorGradient = Fade();
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
			val.AddComponent<DashBladeFx>().Bind(halo, particles, val3);
		}

		internal static void Burst(Vector3 point)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Rubro_Impacto_Faiscas");
			val.transform.position = point;
			Particles(val.transform, burst: true);
			Object.Destroy((Object)val, 0.65f);
		}

		internal static TrailRenderer DashTrail(Transform parent)
		{
			//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_001c: 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)
			Ensure();
			GameObject val = new GameObject("Investida_Rastro_Avanco");
			val.transform.SetParent(parent, false);
			val.transform.localPosition = new Vector3(0f, 0.9f, 0f);
			TrailRenderer obj = val.AddComponent<TrailRenderer>();
			((Renderer)obj).sharedMaterial = sparkMaterial;
			obj.time = 0.16f;
			obj.widthMultiplier = 0.25f;
			obj.minVertexDistance = 0.06f;
			obj.numCapVertices = 2;
			obj.widthCurve = AnimationCurve.Linear(0f, 1f, 1f, 0f);
			obj.colorGradient = Fade();
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return obj;
		}

		private static Gradient Fade()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_001e: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(0.12f, 0.65f, 1f), 0f),
				new GradientColorKey(new Color(0.015f, 0.08f, 0.4f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.8f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}

		private static ParticleSystem Particles(Transform parent, bool burst)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(burst ? "Estilhacos_Rubros" : "Faiscas_Alongadas");
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = !burst;
			((MainModule)(ref main)).duration = 0.5f;
			((MainModule)(ref main)).maxParticles = 48;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.13f, burst ? 0.32f : 0.23f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.022f, burst ? 0.075f : 0.05f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(burst ? 1.2f : 0.15f, burst ? 3.5f : 0.6f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.12f, 0.65f, 1.2f, 0.9f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(burst ? 0.12f : 0f);
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit((float)((!burst) ? 72 : 0));
			if (burst)
			{
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)18)
				});
			}
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)((!burst) ? 5 : 0);
			((ShapeModule)(ref shape)).radius = 0.06f;
			((ShapeModule)(ref shape)).scale = (Vector3)(burst ? Vector3.one : new Vector3(4.8f, 0.05f, 0.02f));
			if (!burst)
			{
				((ShapeModule)(ref shape)).rotation = new Vector3(0f, 180f, 0f);
			}
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(Fade());
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = sparkMaterial;
			component.renderMode = (ParticleSystemRenderMode)1;
			component.lengthScale = 2f;
			component.velocityScale = 0.15f;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			val2.Play();
			return val2;
		}

		internal static void Release()
		{
			DashBladeFx[] array = Object.FindObjectsOfType<DashBladeFx>();
			for (int i = 0; i < array.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array[i]).gameObject);
			}
			Object[] array2 = (Object[])(object)new Object[5]
			{
				(Object)ribbon,
				(Object)bladeMaterial,
				(Object)sparkMaterial,
				(Object)bladeTexture,
				(Object)sparkTexture
			};
			foreach (Object val in array2)
			{
				if (val != (Object)null)
				{
					Object.Destroy(val);
				}
			}
			ribbon = null;
			bladeMaterial = (sparkMaterial = null);
			bladeTexture = (sparkTexture = null);
			Paused = null;
		}
	}
	public sealed class DashBladeFx : MonoBehaviour
	{
		private Transform glow;

		private ParticleSystem sparks;

		private TrailRenderer trail;

		private float age;

		private bool paused;

		internal void Bind(Transform halo, ParticleSystem particles, TrailRenderer tail)
		{
			glow = halo;
			sparks = particles;
			trail = tail;
		}

		private void Update()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			bool flag = DashVisual.Paused?.Invoke() ?? false;
			if (flag != paused)
			{
				paused = flag;
				if (flag)
				{
					sparks.Pause();
				}
				else
				{
					sparks.Play();
				}
				trail.emitting = !flag;
			}
			if (!flag)
			{
				age += Time.deltaTime;
				float num = 1f + 0.08f * Mathf.Sin(age * 31f);
				glow.localScale = new Vector3(1.04f, 3.4f * num, 1f);
			}
		}
	}
	[BepInPlugin("codex.outward.investida.carmesim", "Codex - Resvaldo Lunar", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.investida.carmesim";

		public const int SkillId = 9106920;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = SkillIcon.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (Func<Sprite>)CarmVisual.CreateIcon, (Action<string>)Log.LogWarning);
			patches = new Harmony("codex.outward.investida.carmesim");
			patches.PatchAll(typeof(Plugin).Assembly);
			DashVisual.Paused = delegate
			{
				NetworkLevelLoader instance = NetworkLevelLoader.Instance;
				return instance != null && instance.IsGameplayPaused;
			};
			SL_Item.AddOnInstanceStartListener(9106920, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[InvestidaCarmesim] 1.0.5;treinador;name=Resvaldo Lunar;cooldown40s;approved Sword_Dash/combat/dash unchanged");
		}

		private void Build()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				DashClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				DashVisual.Ensure();
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106920) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106920);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106920;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Resvaldo Lunar";
				((SL_Item)val2).Description = "Avanco curto com animacao Sword_Dash externa e corte azul alongado.100 dano-base:contato fisico bloqueavel ou feixe decomposicao. Um acerto por alvo.24vigor,40s recarga. Requer espada1H/2H.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 24f;
				((SL_Skill)val2).Cooldown = 40f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[2]
				{
					default(WeaponType),
					(WeaponType)51
				};
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[InvestidaCarmesim] PRONTO:9106920;Resvaldo Lunar;Human=True;one source strike;24vigor/40s;visual USER APPROVED");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[InvestidaCarmesim] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106920)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			DashMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								DashMotion dashMotion = ((Component)value).GetComponent<DashMotion>();
								if ((Object)(object)dashMotion == (Object)null)
								{
									try
									{
										dashMotion = ((Component)value).gameObject.AddComponent<DashMotion>();
										dashMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)dashMotion != (Object)null)
										{
											Object.Destroy((Object)(object)dashMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[InvestidaCarmesim] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = dashMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			DashMotion[] array = Object.FindObjectsOfType<DashMotion>();
			foreach (DashMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			DashWave[] array2 = Object.FindObjectsOfType<DashWave>();
			for (int i = 0; i < array2.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			}
			Harmony obj2 = patches;
			if (obj2 != null)
			{
				obj2.UnpatchAll("codex.outward.investida.carmesim");
			}
			DashClip.Dispose();
			DashVisual.Release();
			SkillIcon.Release(icon);
			CarmVisual.Release();
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106920)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<DashMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			DashMotion component = ((Component)__instance).GetComponent<DashMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106920)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter != null)
				{
					((Component)ownerCharacter).GetComponent<DashMotion>()?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<DashMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				DashMotion dashMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<DashMotion>() : null);
				if (((Item)__instance).ItemID == 9106920)
				{
					__result = dashMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && dashMotion != null && dashMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			DashMotion component = ((Component)__instance).GetComponent<DashMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}

BepInEx/plugins/Codex_Lanca_Tempestade/CodexLancaTempestade.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexHumanoidExtras;
using CodexSkillIcons;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexSkillIcons
{
	internal static class SkillIcon
	{
		private static readonly HashSet<Sprite> owned = new HashSet<Sprite>();

		internal static Sprite Load(string folder, Func<Sprite> fallback, Action<string> warning)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = null;
			Sprite val2 = null;
			try
			{
				val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					name = "Codex_SkillIcon_Painted",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)2
				};
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, "UI", "skill-icon.png")), false) || ((Texture)val).width != 512 || ((Texture)val).height != 512)
				{
					throw new InvalidDataException("Expected512x512 skill-icon.png");
				}
				val.Apply(true, true);
				val2 = Sprite.Create(val, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidDataException("Icon Sprite unavailable");
				}
				owned.Add(val2);
				return val2;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				warning?.Invoke("ICON_FALLBACK:" + ex.Message);
				return fallback();
			}
		}

		internal static void Release(Sprite sprite)
		{
			if (!((Object)(object)sprite == (Object)null) && owned.Remove(sprite))
			{
				Object.Destroy((Object)(object)sprite.texture);
				Object.Destroy((Object)(object)sprite);
			}
		}
	}
}
namespace CodexLancaTempestade
{
	[BepInPlugin("codex.outward.lanca.tempestade", "Codex - Lanca da Tempestade", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.lanca.tempestade";

		public const int SkillId = 9106950;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = SkillIcon.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (Func<Sprite>)SpearVisual.CreateIcon, (Action<string>)Log.LogWarning);
			patches = new Harmony("codex.outward.lanca.tempestade");
			patches.PatchAll(typeof(Plugin).Assembly);
			SpearVisual.Paused = delegate
			{
				NetworkLevelLoader instance = NetworkLevelLoader.Instance;
				return instance != null && instance.IsGameplayPaused;
			};
			SL_Item.AddOnInstanceStartListener(9106950, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[LancaTempestade] 1.0.2;treinador;12body lightning arcs during cast;OverhandThrow/combat unchanged;PENDING USER");
		}

		private void Build()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				SpearClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				SpearVisual.Ensure();
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106950) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106950);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106950;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Lanca da Tempestade";
				((SL_Item)val2).Description = "Arremessa uma lanca de raios azuis com animacao externa.150 dano eletrico,60 impacto,alcance35m. Atinge o primeiro inimigo ou obstaculo;explosao apenas visual. Especial a distancia nao bloqueavel.25vigor,40s recarga. Nao exige arma.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 25f;
				((SL_Skill)val2).Cooldown = 40f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[LancaTempestade] PRONTO:9106950;Lanca da Tempestade;Human=True;single projectile;25vigor/40s;PENDING USER");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[LancaTempestade] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106950)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			SpearMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								SpearMotion spearMotion = ((Component)value).GetComponent<SpearMotion>();
								if ((Object)(object)spearMotion == (Object)null)
								{
									try
									{
										spearMotion = ((Component)value).gameObject.AddComponent<SpearMotion>();
										spearMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)spearMotion != (Object)null)
										{
											Object.Destroy((Object)(object)spearMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[LancaTempestade] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = spearMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			SpearMotion[] array = Object.FindObjectsOfType<SpearMotion>();
			foreach (SpearMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			SpearProjectile[] array2 = Object.FindObjectsOfType<SpearProjectile>();
			for (int i = 0; i < array2.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			}
			Harmony obj2 = patches;
			if (obj2 != null)
			{
				obj2.UnpatchAll("codex.outward.lanca.tempestade");
			}
			SpearClip.Dispose();
			SpearVisual.Release();
			SkillIcon.Release(icon);
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106950)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<SpearMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			SpearMotion component = ((Component)__instance).GetComponent<SpearMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106950)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter != null)
				{
					((Component)ownerCharacter).GetComponent<SpearMotion>()?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<SpearMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				SpearMotion spearMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<SpearMotion>() : null);
				if (((Item)__instance).ItemID == 9106950)
				{
					__result = spearMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && spearMotion != null && spearMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			SpearMotion component = ((Component)__instance).GetComponent<SpearMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class SpearAttack
	{
		internal static Character Victim(Character owner, Collider collider)
		{
			Hitbox componentInParent = ((Component)collider).GetComponentInParent<Hitbox>();
			Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val != (Object)(object)owner) || !val.Alive || val.Invincible || val.IsLocalPlayer || !((Object)(object)owner.TargetingSystem != (Object)null) || !owner.TargetingSystem.IsTargetable(val))
			{
				return null;
			}
			return val;
		}

		internal static void Release(Character owner)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_00e2: 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_00ea: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			Transform boneTransform = owner.Animator.GetBoneTransform((HumanBodyBones)18);
			Vector3 val = (((Object)(object)boneTransform != (Object)null) ? boneTransform.position : owner.CenterPosition);
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Linecast(owner.CenterPosition, val, ref val2, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				SpearVisual.Burst(((RaycastHit)(ref val2)).point);
				Plugin.Log.LogMessage((object)"[LancaTempestade] RELEASE_BLOCKED;wall between capsule and hand");
				return;
			}
			Vector3 val3 = Vector3.ProjectOnPlane(((Component)owner).transform.forward, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			if (((Vector3)(ref normalized)).sqrMagnitude < 0.5f)
			{
				return;
			}
			TargetingSystem targetingSystem = owner.TargetingSystem;
			Character val4 = ((targetingSystem != null) ? targetingSystem.LockedCharacter : null);
			int num;
			if ((Object)(object)val4 != (Object)null && val4.Alive && !val4.IsLocalPlayer && owner.TargetingSystem.IsTargetable(val4))
			{
				val3 = val4.CenterPosition - val;
				if (((Vector3)(ref val3)).sqrMagnitude <= 1225f && Vector3.Angle(normalized, val4.CenterPosition - val) < 75f)
				{
					num = ((!Physics.Linecast(val, val4.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1)) ? 1 : 0);
					goto IL_0115;
				}
			}
			num = 0;
			goto IL_0115;
			IL_0115:
			bool flag = (byte)num != 0;
			val3 = (flag ? val4.CenterPosition : (owner.CenterPosition + normalized * 12f)) - val;
			Vector3 val5 = ((Vector3)(ref val3)).normalized;
			if (((Vector3)(ref val5)).sqrMagnitude < 0.5f)
			{
				val5 = normalized;
			}
			GameObject val6 = new GameObject("LancaTempestade_Projetil");
			val6.transform.position = val;
			val6.transform.rotation = Quaternion.LookRotation(val5, Vector3.up);
			val6.AddComponent<SpearProjectile>().Bind(owner, val5);
			Plugin.Log.LogMessage((object)("[LancaTempestade] RELEASE;150Electric/60impact;range35m;locked=" + flag));
		}
	}
	public sealed class SpearProjectile : MonoBehaviour
	{
		private Character owner;

		private Vector3 direction;

		private float distance;

		private float age;

		private int mask;

		private bool spent;

		internal void Bind(Character player, Vector3 facing)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			owner = player;
			direction = facing;
			mask = Global.GeneralEnvironmentMask | LayerMask.GetMask(new string[1] { "Hitbox" });
			SpearVisual.Spear(((Component)this).transform, trail: true);
		}

		private void Update()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if (spent)
			{
				return;
			}
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				spent = true;
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				age += Time.deltaTime;
				if (age > 2.5f)
				{
					spent = true;
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				float num = SpearFlight.Step(distance, Time.deltaTime);
				if (num <= 0f)
				{
					spent = true;
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 0.32f, mask, (QueryTriggerInteraction)2);
				Collider[] array2 = array;
				foreach (Collider collider in array2)
				{
					if (Wall(collider))
					{
						Impact(((Component)this).transform.position);
						return;
					}
				}
				Array.Sort(array, delegate(Collider a, Collider b)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					//IL_001c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: 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_0043: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: Unknown result type (might be due to invalid IL or missing references)
					//IL_004d: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val2 = a.ClosestPoint(((Component)this).transform.position) - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					val2 = b.ClosestPoint(((Component)this).transform.position) - ((Component)this).transform.position;
					return sqrMagnitude.CompareTo(((Vector3)(ref val2)).sqrMagnitude);
				});
				array2 = array;
				foreach (Collider collider2 in array2)
				{
					if (Damage(collider2))
					{
						return;
					}
				}
				RaycastHit[] array3 = Physics.SphereCastAll(((Component)this).transform.position, 0.32f, direction, num, mask, (QueryTriggerInteraction)2);
				Array.Sort(array3, delegate(RaycastHit a, RaycastHit b)
				{
					int num2 = ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance);
					return (num2 == 0) ? ((!Wall(((RaycastHit)(ref a)).collider)) ? (Wall(((RaycastHit)(ref b)).collider) ? 1 : 0) : (-1)) : num2;
				});
				RaycastHit[] array4 = array3;
				for (int i = 0; i < array4.Length; i++)
				{
					RaycastHit val = array4[i];
					if (Wall(((RaycastHit)(ref val)).collider))
					{
						Impact(((RaycastHit)(ref val)).point);
						return;
					}
					if (Damage(((RaycastHit)(ref val)).collider))
					{
						return;
					}
				}
				Transform transform = ((Component)this).transform;
				transform.position += direction * num;
				distance += num;
				if (distance >= 34.999f)
				{
					spent = true;
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private bool Wall(Collider collider)
		{
			if (!collider.isTrigger && (Global.GeneralEnvironmentMask & (1 << ((Component)collider).gameObject.layer)) != 0)
			{
				return (Object)(object)((Component)collider).GetComponentInParent<Character>() == (Object)null;
			}
			return false;
		}

		private bool Damage(Collider collider)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_007b: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (spent)
			{
				return true;
			}
			Character val = SpearAttack.Victim(owner, collider);
			if ((Object)(object)val == (Object)null || Physics.Linecast(((Component)this).transform.position, val.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			spent = true;
			val.ReceiveHit((Object)null, new DamageList((Types)3, 150f), direction, val.CenterPosition, 45f, 1f, owner, 60f, true);
			SpearVisual.Burst(val.CenterPosition);
			Plugin.Log.LogMessage((object)("[LancaTempestade] HIT:" + val.Name + ";150Electric/60impact;no burst damage"));
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return true;
		}

		private void Impact(Vector3 position)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!spent)
			{
				spent = true;
				SpearVisual.Burst(position);
				Plugin.Log.LogMessage((object)"[LancaTempestade] WALL_IMPACT");
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	public sealed class SpearCastFx : MonoBehaviour
	{
		private static readonly HumanBodyBones[,] Paths;

		internal static readonly HashSet<SpearCastFx> Live;

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

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

		private readonly List<LineRenderer> lines = new List<LineRenderer>();

		private Animator animator;

		private float age;

		internal static GameObject Attach(Animator animator, Transform owner)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if ((Object)(object)animator == (Object)null || !animator.isHuman)
			{
				return null;
			}
			GameObject val = new GameObject("Tempestade_RaiosDuranteCast");
			val.transform.SetParent(owner, false);
			try
			{
				val.AddComponent<SpearCastFx>().Bind(animator);
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		private void Bind(Animator source)
		{
			//IL_001b: 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)
			animator = source;
			SpearVisual.Ensure();
			for (int i = 0; i < Paths.GetLength(0); i++)
			{
				Transform boneTransform = source.GetBoneTransform(Paths[i, 0]);
				Transform boneTransform2 = source.GetBoneTransform(Paths[i, 1]);
				if (!((Object)(object)boneTransform == (Object)null) && !((Object)(object)boneTransform2 == (Object)null))
				{
					LineRenderer val = SpearVisual.Line(((Component)this).transform, "ArcoCorporal_" + i, 9, (i < 4) ? 0.03f : 0.022f);
					val.useWorldSpace = true;
					starts.Add(boneTransform);
					ends.Add(boneTransform2);
					lines.Add(val);
				}
			}
			Live.Add(this);
			Sample(0f);
		}

		internal void Sample(float time)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < lines.Count; i++)
			{
				if (!((Object)(object)starts[i] == (Object)null) && !((Object)(object)ends[i] == (Object)null) && !((Object)(object)lines[i] == (Object)null))
				{
					Vector3 position = starts[i].position;
					Vector3 position2 = ends[i].position;
					Vector3 val = position2 - position;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Vector3 val2 = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.forward : ((Component)this).transform.forward);
					Camera main = Camera.main;
					Vector3 val3;
					if (!((Object)(object)main != (Object)null))
					{
						val3 = val2;
					}
					else
					{
						val = ((Component)main).transform.position - (position + position2) * 0.5f;
						val3 = ((Vector3)(ref val)).normalized;
					}
					Vector3 val4 = val3 * ((i < 4) ? 0.14f : 0.27f);
					Vector3 val5 = Vector3.Cross(normalized, Vector3.up);
					if (((Vector3)(ref val5)).sqrMagnitude < 0.01f)
					{
						val5 = Vector3.Cross(normalized, Vector3.right);
					}
					((Vector3)(ref val5)).Normalize();
					val = Vector3.Cross(normalized, val5);
					Vector3 normalized2 = ((Vector3)(ref val)).normalized;
					float num = 0.65f + 0.25f * Mathf.Sin(time * 24f + (float)i * 1.4f);
					lines[i].startColor = new Color(0.7f, 0.92f, 1f, num);
					lines[i].endColor = new Color(0.12f, 0.5f, 1f, num * 0.6f);
					for (int j = 0; j < 9; j++)
					{
						float num2 = (float)j / 8f;
						float num3 = Mathf.Sin(num2 * (float)Math.PI);
						float num4 = time * 45f + (float)i * 5.2f + (float)j * 2.7f;
						Vector3 val6 = val5 * (Mathf.Sin(num4) * 0.055f * num3) + normalized2 * (Mathf.Cos(num4 * 1.31f) * 0.035f * num3);
						lines[i].SetPosition(j, Vector3.Lerp(position, position2, num2) + val4 + val6);
					}
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)animator == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Func<bool> paused = SpearVisual.Paused;
			if (paused == null || !paused())
			{
				age += Time.deltaTime;
				Sample(age);
			}
		}

		private void OnDestroy()
		{
			Live.Remove(this);
		}

		static SpearCastFx()
		{
			HumanBodyBones[,] array = new HumanBodyBones[12, 2];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			Paths = array;
			Live = new HashSet<SpearCastFx>();
		}
	}
	internal static class SpearClip
	{
		internal const string Prefix = "LancaTempestadeHumanoid_";

		internal const float Duration = 1.3333334f;

		internal const string Hash = "652F63DCF872A14B50EFFA24965E2F2763EB35CF4FC77938DDD6842F6EFA7AF5";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_lanca_tempestade");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "652F63DCF872A14B50EFFA24965E2F2763EB35CF4FC77938DDD6842F6EFA7AF5")
					{
						throw new InvalidDataException("Compiled punch SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled punch bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexTempestade_OverhandThrow");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 1.3333334f) > 0.001f)
				{
					throw new InvalidDataException("Expected official external Humanoid OverhandThrow");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "LancaTempestadeHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	public sealed class SpearMotion : MonoBehaviour
	{
		private Character player;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private SpearTimeline clock;

		private bool nativeCast;

		private float normalized;

		private GameObject aura;

		private GameObject castFx;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (SpearClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding && (Object)(object)player.CharacterController != (Object)null && ((Collider)player.CharacterController).enabled)
				{
					return (Object)(object)player.Animator.avatar == (Object)(object)avatar;
				}
				return false;
			}
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				SpearClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			if (((Item)value).ItemID != 9106950 || !CanBegin)
			{
				return false;
			}
			try
			{
				lease.Acquire(SpearClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new SpearTimeline();
				nativeCast = false;
				normalized = 0f;
				Plugin.Log.LogMessage((object)("[LancaTempestade] CAST;OverhandThrow;nativeAvatar=" + ((Object)avatar).name + ";25vigor/40s"));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && !((Object)(object)value != (Object)(object)skill) && !tail.NativeEnded)
			{
				tail.EndNative();
				Plugin.Log.LogMessage((object)"[LancaTempestade] NATIVEEND;retain override through blend-out");
			}
		}

		private void LateUpdate()
		{
			//IL_02a4: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				bool observed = tail.Observed;
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (!observed && tail.Observed)
				{
					Plugin.Log.LogMessage((object)"[LancaTempestade] EXTERNALACTIVE;Human=True;AvatarUNCHANGED");
				}
				if (flag)
				{
					try
					{
						clock.Observe(normalized);
						if (clock.Started && !nativeCast)
						{
							if (!OwnCast)
							{
								Fail("Native receiver lost before cost");
								return;
							}
							NativeInvocation = true;
							nativeCast = true;
							((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
							NativeInvocation = false;
							if (!Active || !OwnCast)
							{
								return;
							}
							Transform boneTransform = player.Animator.GetBoneTransform((HumanBodyBones)18);
							if ((Object)(object)boneTransform != (Object)null)
							{
								aura = SpearVisual.Held(boneTransform, ((Component)player).transform.forward);
							}
							try
							{
								castFx = SpearCastFx.Attach(player.Animator, ((Component)player).transform);
							}
							catch (Exception ex)
							{
								Plugin.Log.LogWarning((object)("[LancaTempestade] CASTFX_FAILED:" + ex.Message));
							}
						}
						if ((Object)(object)aura != (Object)null)
						{
							aura.transform.rotation = Quaternion.LookRotation(((Component)player).transform.forward, Vector3.up);
						}
						if (clock.TryStrike() && nativeCast)
						{
							if ((Object)(object)aura != (Object)null)
							{
								Object.Destroy((Object)(object)aura);
								aura = null;
							}
							SpearAttack.Release(player);
						}
					}
					catch (Exception ex2)
					{
						Fail("RELEASEFAILED:" + ex2);
						return;
					}
					finally
					{
						NativeInvocation = false;
					}
				}
				if (tail.CanRestore)
				{
					Cancel("native blend-out complete");
				}
				else if (tail.TimedOut(1.3333334f))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("LancaTempestadeHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[LancaTempestade] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			clock?.Cancel();
			bool active = Active;
			skill = null;
			tail = null;
			clock = null;
			nativeCast = false;
			if ((Object)(object)aura != (Object)null)
			{
				Object.Destroy((Object)(object)aura);
				aura = null;
			}
			if ((Object)(object)castFx != (Object)null)
			{
				Object.Destroy((Object)(object)castFx);
				castFx = null;
			}
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[LancaTempestade] RESTORED;reason=" + reason + ";AvatarUNCHANGED"));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[LancaTempestade] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal sealed class SpearTimeline
	{
		internal const float StartAt = 0.025f;

		internal const float StrikeAt = 0.25f;

		private float progress;

		private bool struck;

		private bool cancelled;

		internal bool Started
		{
			get
			{
				if (!cancelled)
				{
					return progress >= 0.025f;
				}
				return false;
			}
		}

		internal void Observe(float value)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, value);
			}
		}

		internal bool TryStrike()
		{
			if (cancelled || struck || progress < 0.25f)
			{
				return false;
			}
			struck = true;
			return true;
		}

		internal void Cancel()
		{
			cancelled = true;
		}
	}
	internal static class SpearFlight
	{
		internal const float Range = 35f;

		internal const float Speed = 28f;

		internal const float Radius = 0.32f;

		internal const float Damage = 150f;

		internal const float Impact = 60f;

		internal static float Step(float distance, float dt)
		{
			if (float.IsNaN(dt) || float.IsInfinity(dt) || dt <= 0f || distance >= 35f)
			{
				return 0f;
			}
			return Math.Min(28f * dt, Math.Max(0f, 35f - distance));
		}
	}
	internal static class SpearVisual
	{
		internal static Func<bool> Paused;

		internal static readonly HashSet<SpearFx> Live = new HashSet<SpearFx>();

		private static Texture2D streak;

		private static Texture2D soft;

		private static Texture2D iconTexture;

		private static Material glow;

		private static Material spark;

		private static Mesh mesh;

		private static Sprite fallback;

		internal static void Ensure()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//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_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Expected O, but got Unknown
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Expected O, but got Unknown
			//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_03d0: 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_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)streak != (Object)null)
			{
				return;
			}
			Shader val = Shader.Find("Legacy Shaders/Particles/Additive");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Lightning shader unavailable");
			}
			streak = new Texture2D(2048, 256, (TextureFormat)4, true)
			{
				name = "Tempestade_Plasma2K",
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[524288];
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 2048; j++)
				{
					float num = (float)j / 2047f;
					float num2 = ((float)i - 127.5f) / 127.5f;
					float num3 = Mathf.Pow(Mathf.Max(0f, 1f - Mathf.Abs(num2)), 2f);
					float num4 = Mathf.Pow(Mathf.Max(0f, Mathf.Cos(num2 * 24f + num * 35f + Mathf.Sin(num * 40f) * 0.6f)), 7f);
					array[i * 2048 + j] = Color32.op_Implicit(new Color(0.15f + num3 * 0.55f, 0.42f + num3 * 0.5f, 1f, Mathf.Clamp01((num3 * 0.65f + num4 * 0.25f) * (1f - num2 * num2))));
				}
			}
			streak.SetPixels32(array);
			streak.Apply(true, true);
			glow = new Material(val)
			{
				name = "Tempestade_SharedPlasma",
				mainTexture = (Texture)(object)streak
			};
			glow.SetColor("_TintColor", new Color(0.3f, 0.65f, 1f, 0.6f));
			soft = new Texture2D(256, 256, (TextureFormat)4, true)
			{
				name = "Tempestade_SoftRound",
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			array = (Color32[])(object)new Color32[65536];
			for (int k = 0; k < 256; k++)
			{
				for (int l = 0; l < 256; l++)
				{
					float num5 = ((float)l - 127.5f) / 127.5f;
					float num6 = ((float)k - 127.5f) / 127.5f;
					array[k * 256 + l] = Color32.op_Implicit(new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Max(0f, 1f - num5 * num5 - num6 * num6), 3f)));
				}
			}
			soft.SetPixels32(array);
			soft.Apply(true, true);
			spark = new Material(val)
			{
				name = "Tempestade_SharedSpark",
				mainTexture = (Texture)(object)soft
			};
			spark.SetColor("_TintColor", new Color(0.2f, 0.65f, 1f, 0.55f));
			Vector3[] array2 = (Vector3[])(object)new Vector3[42];
			Vector2[] array3 = (Vector2[])(object)new Vector2[42];
			Color[] array4 = (Color[])(object)new Color[42];
			List<int> list = new List<int>();
			float[] array5 = new float[6] { -0.95f, -0.75f, 0.55f, 0.72f, 0.86f, 1.18f };
			float[] array6 = new float[6] { 0f, 0.035f, 0.035f, 0.12f, 0.07f, 0f };
			for (int m = 0; m < 6; m++)
			{
				for (int n = 0; n < 7; n++)
				{
					int num7 = m * 7 + n;
					float num8 = (float)n * (float)Math.PI * 2f / 6f;
					array2[num7] = new Vector3(Mathf.Cos(num8) * array6[m], Mathf.Sin(num8) * array6[m], array5[m]);
					array3[num7] = new Vector2((array5[m] + 0.95f) / 2.13f, (float)n / 6f);
					array4[num7] = new Color(0.25f, 0.7f, 1f, 0.8f);
					if (m < 5 && n < 6)
					{
						list.AddRange(new int[6]
						{
							num7,
							num7 + 8,
							num7 + 7,
							num7,
							num7 + 1,
							num7 + 8
						});
					}
				}
			}
			mesh = new Mesh
			{
				name = "Tempestade_SharedSpearMesh",
				vertices = array2,
				uv = array3,
				colors = array4,
				triangles = list.ToArray()
			};
			mesh.RecalculateNormals();
			mesh.RecalculateBounds();
		}

		internal static GameObject Held(Transform hand, Vector3 direction)
		{
			//IL_0005: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_003a: Expected O, but got Unknown
			GameObject val = new GameObject("Tempestade_LancaNaMao");
			val.transform.SetParent(hand, false);
			val.transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
			Spear(val.transform, trail: false);
			return val;
		}

		internal static void Spear(Transform parent, bool trail)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			GameObject val = new GameObject("LancaEletrica");
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = glow;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			val.AddComponent<SpearFx>().BindSpear();
			if (trail)
			{
				TrailRenderer obj2 = val.AddComponent<TrailRenderer>();
				((Renderer)obj2).sharedMaterial = glow;
				obj2.time = 0.13f;
				obj2.minVertexDistance = 0.12f;
				obj2.startWidth = 0.08f;
				obj2.endWidth = 0f;
				obj2.startColor = new Color(0.3f, 0.75f, 1f, 0.5f);
				obj2.endColor = new Color(0f, 0.1f, 1f, 0f);
				((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
			}
		}

		internal static LineRenderer Line(Transform parent, string name, int count, float width)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			obj.useWorldSpace = false;
			obj.positionCount = count;
			obj.widthMultiplier = width;
			((Renderer)obj).sharedMaterial = glow;
			obj.startColor = new Color(0.3f, 0.75f, 1f, 0.7f);
			obj.endColor = new Color(0.08f, 0.3f, 1f, 0.4f);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return obj;
		}

		internal static void Burst(Vector3 position)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			GameObject val = new GameObject("Tempestade_ImpactoEletrico");
			val.transform.position = position;
			val.AddComponent<SpearFx>().BindBurst();
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).duration = 0.5f;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.2f, 0.55f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.035f, 0.09f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(2f, 5f);
			((MainModule)(ref main)).maxParticles = 20;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.3f, 0.8f, 1f, 0.7f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).enabled = false;
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.05f;
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(new Color(0.1f, 0.3f, 1f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(1f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
			((Renderer)((Component)val2).GetComponent<ParticleSystemRenderer>()).sharedMaterial = spark;
			val2.Play();
			val2.Emit(18);
		}

		internal static Sprite CreateIcon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)fallback != (Object)null)
			{
				return fallback;
			}
			iconTexture = new Texture2D(128, 128, (TextureFormat)4, true);
			Color32[] array = (Color32[])(object)new Color32[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j - 63.5f) / 63.5f;
					float num2 = ((float)i - 63.5f) / 63.5f;
					float num3 = Mathf.Abs(num - num2);
					array[i * 128 + j] = Color32.op_Implicit(new Color(0.2f, 0.7f, 1f, Mathf.Clamp01(1f - num3 * 25f) * Mathf.Clamp01((1f - Mathf.Abs(num)) * 4f)));
				}
			}
			iconTexture.SetPixels32(array);
			iconTexture.Apply(true, true);
			fallback = Sprite.Create(iconTexture, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 128f);
			return fallback;
		}

		internal static void Release()
		{
			foreach (SpearCastFx item in new List<SpearCastFx>(SpearCastFx.Live))
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			SpearCastFx.Live.Clear();
			foreach (SpearFx item2 in new List<SpearFx>(Live))
			{
				if ((Object)(object)item2 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item2).gameObject);
				}
			}
			Live.Clear();
			Object[] array = (Object[])(object)new Object[7]
			{
				(Object)streak,
				(Object)soft,
				(Object)glow,
				(Object)spark,
				(Object)mesh,
				(Object)fallback,
				(Object)iconTexture
			};
			foreach (Object val in array)
			{
				if (val != (Object)null)
				{
					Object.Destroy(val);
				}
			}
			streak = (soft = (iconTexture = null));
			glow = (spark = null);
			mesh = null;
			fallback = null;
		}
	}
	public sealed class SpearFx : MonoBehaviour
	{
		private LineRenderer[] arcs;

		private float age;

		private bool burst;

		private bool paused;

		private ParticleSystem particles;

		private TrailRenderer trail;

		internal void BindSpear()
		{
			arcs = (LineRenderer[])(object)new LineRenderer[4];
			for (int i = 0; i < 4; i++)
			{
				arcs[i] = SpearVisual.Line(((Component)this).transform, "FioDeRaio", 13, 0.018f);
			}
			SpearVisual.Live.Add(this);
			Sample(0f);
		}

		internal void BindBurst()
		{
			burst = true;
			arcs = (LineRenderer[])(object)new LineRenderer[8];
			for (int i = 0; i < 8; i++)
			{
				arcs[i] = SpearVisual.Line(((Component)this).transform, "RaioDoImpacto", 7, 0.023f);
			}
			SpearVisual.Live.Add(this);
			Sample(0.05f);
		}

		internal void Sample(float time)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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)
			for (int i = 0; i < arcs.Length; i++)
			{
				LineRenderer val = arcs[i];
				for (int j = 0; j < val.positionCount; j++)
				{
					float num = (float)j / (float)(val.positionCount - 1);
					float num2 = (float)i * 1.77f + (float)j * 2.63f + time * 38f;
					if (!burst)
					{
						float num3 = Mathf.Sin(num * (float)Math.PI);
						val.SetPosition(j, new Vector3(Mathf.Sin(num2) * 0.075f * num3, Mathf.Cos(num2 * 1.17f) * 0.075f * num3, -0.85f + num * 1.95f));
					}
					else
					{
						float num4 = (float)i * (float)Math.PI * 2f / (float)arcs.Length;
						float num5 = num * Mathf.Min(1.15f, time * 4f);
						val.SetPosition(j, new Vector3(Mathf.Cos(num4) * num5, Mathf.Sin(num4) * num5, Mathf.Sin(num2) * 0.07f * num));
					}
				}
				if (burst)
				{
					float num6 = Mathf.Clamp01(1f - time / 0.6f);
					val.startColor = new Color(0.4f, 0.8f, 1f, num6 * 0.6f);
					val.endColor = new Color(0.1f, 0.4f, 1f, num6 * 0.2f);
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)particles == (Object)null)
			{
				particles = ((Component)this).GetComponent<ParticleSystem>();
			}
			if ((Object)(object)trail == (Object)null)
			{
				trail = ((Component)this).GetComponent<TrailRenderer>();
			}
			bool flag = SpearVisual.Paused?.Invoke() ?? false;
			if (flag != paused)
			{
				if ((Object)(object)particles != (Object)null)
				{
					if (flag)
					{
						particles.Pause();
					}
					else
					{
						particles.Play();
					}
				}
				if ((Object)(object)trail != (Object)null)
				{
					trail.emitting = !flag;
				}
				paused = flag;
			}
			if (!flag)
			{
				age += Time.deltaTime;
				Sample(age);
				if (burst && age > 0.7f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private void OnDestroy()
		{
			SpearVisual.Live.Remove(this);
		}
	}
}

BepInEx/plugins/Codex_Marca_Carrasco/CodexMarcaCarrasco.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexHumanoidExtras;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexMarcaCarrasco
{
	internal static class MarkClip
	{
		internal const string Prefix = "MarcaCarrascoHumanoid_";

		internal const float Duration = 1.3f;

		internal const string Hash = "63120F66BAAB646552097C29DCF02D64F9F231514CD0591B029BB8A8CC669A14";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_marca_carrasco");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "63120F66BAAB646552097C29DCF02D64F9F231514CD0591B029BB8A8CC669A14")
					{
						throw new InvalidDataException("Compiled mark bundle SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled mark bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexMarca_SwordRegularA");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 1.3f) > 0.001f)
				{
					throw new InvalidDataException("Expected official external Humanoid Sword_Regular_A+Rec");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "MarcaCarrascoHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	public sealed class MarkField : MonoBehaviour
	{
		private const float Delay = 2f;

		private const float Interval = 0.3f;

		private const float Radius = 1.6f;

		private const float Damage = 35f;

		private const float Impact = 12f;

		private Character owner;

		private Vector3 point;

		private float age;

		private int next;

		internal void Bind(Character value, Vector3 ground)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			owner = value;
			point = ground;
			((Component)this).transform.position = ground;
			MarkVisual.Ring(((Component)this).transform);
			MarkVisual.Sound((Sounds)12976, point);
			Plugin.Log.LogMessage((object)"[MarcaCarrasco] MARCADA;fixed ground point;delay2s;3x35Ethereal/12impact");
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else if (!instance.IsGameplayPaused)
			{
				age += Time.deltaTime;
				while (next < 3 && age >= 2f + (float)next * 0.3f)
				{
					Strike(next);
					next++;
				}
				if (age > 3.45f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private void Strike(int index)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_01bc: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			MarkVisual.Slash(point, index);
			MarkVisual.Sound((Sounds)13182, point);
			int num = 0;
			HashSet<Character> hashSet = new HashSet<Character>();
			Collider[] array = Physics.OverlapSphere(point + Vector3.up * 1.1f, 1.6f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox componentInParent = ((Component)array[i]).GetComponentInParent<Hitbox>();
				Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
				if (!((Object)(object)val == (Object)null) && hashSet.Add(val) && !((Object)(object)val == (Object)(object)owner) && val.Alive && !val.Invincible && !val.IsLocalPlayer && !((Object)(object)owner.TargetingSystem == (Object)null) && owner.TargetingSystem.IsTargetable(val) && !(Mathf.Abs(val.CenterPosition.y - point.y) > 2.3f) && !Physics.Linecast(point + Vector3.up * 0.8f, val.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
				{
					Vector3 val2 = val.CenterPosition - owner.CenterPosition;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					val.ReceiveHit((Object)null, new DamageList((Types)1, 35f), normalized, val.CenterPosition, 45f, 1f, owner, 12f, true);
					num++;
				}
			}
			if (num > 0)
			{
				MarkVisual.Sound((Sounds)12974, point);
			}
			Plugin.Log.LogMessage((object)("[MarcaCarrasco] CORTE:" + (index + 1) + "/3;hits=" + num));
		}
	}
	public sealed class MarkMotion : MonoBehaviour
	{
		private Character player;

		private Character target;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private MarkTimeline clock;

		private bool nativeCast;

		private float normalized;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (MarkClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding && (Object)(object)player.Animator.avatar == (Object)(object)avatar)
				{
					return (Object)(object)MarkTarget.Find(player) != (Object)null;
				}
				return false;
			}
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				MarkClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			if (((Item)value).ItemID != 9106970 || !CanBegin)
			{
				return false;
			}
			try
			{
				target = MarkTarget.Find(player);
				if ((Object)(object)target == (Object)null)
				{
					return false;
				}
				lease.Acquire(MarkClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new MarkTimeline();
				nativeCast = false;
				normalized = 0f;
				Plugin.Log.LogMessage((object)("[MarcaCarrasco] CAST;Sword_Regular_A+Rec;target=" + target.Name + ";nativeAvatar=" + ((Object)avatar).name));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && (Object)(object)value == (Object)(object)skill && !tail.NativeEnded)
			{
				tail.EndNative();
			}
		}

		private void LateUpdate()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				bool observed = tail.Observed;
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (!observed && tail.Observed)
				{
					Plugin.Log.LogMessage((object)"[MarcaCarrasco] EXTERNALACTIVE;Human=True;AvatarUNCHANGED");
				}
				if (flag)
				{
					try
					{
						clock.Observe(normalized);
						if (clock.Started && !nativeCast)
						{
							if (!OwnCast)
							{
								Fail("Native receiver lost before cost");
								return;
							}
							NativeInvocation = true;
							nativeCast = true;
							((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
							NativeInvocation = false;
							if (!Active || !OwnCast)
							{
								return;
							}
						}
						if (clock.TryRelease() && nativeCast)
						{
							if (MarkTarget.Valid(player, target))
							{
								new GameObject("MarcaCarrasco_TresLaminas").AddComponent<MarkField>().Bind(player, MarkTarget.Ground(target));
							}
							else
							{
								Plugin.Log.LogMessage((object)"[MarcaCarrasco] TARGET_LOST;no mark");
							}
						}
					}
					catch (Exception ex)
					{
						Fail("RELEASEFAILED:" + ex);
						return;
					}
					finally
					{
						NativeInvocation = false;
					}
				}
				if (tail.CanRestore)
				{
					Cancel("native blend-out complete");
				}
				else if (tail.TimedOut(1.3f))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("MarcaCarrascoHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[MarcaCarrasco] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			clock?.Cancel();
			bool active = Active;
			skill = null;
			target = null;
			tail = null;
			clock = null;
			nativeCast = false;
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[MarcaCarrasco] RESTORED;reason=" + reason + ";AvatarUNCHANGED"));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[MarcaCarrasco] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal static class MarkTarget
	{
		internal const float Range = 15f;

		internal static Character Find(Character owner)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)owner == (Object)null || (Object)(object)owner.TargetingSystem == (Object)null)
			{
				return null;
			}
			Character lockedCharacter = owner.TargetingSystem.LockedCharacter;
			if (Valid(owner, lockedCharacter))
			{
				return lockedCharacter;
			}
			Character result = null;
			float num = float.MaxValue;
			HashSet<Character> hashSet = new HashSet<Character>();
			Collider[] array = Physics.OverlapSphere(owner.CenterPosition, 15f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox componentInParent = ((Component)array[i]).GetComponentInParent<Hitbox>();
				Character val = ((componentInParent != null) ? componentInParent.OwnerChar : null);
				if (hashSet.Add(val) && Valid(owner, val))
				{
					Vector3 val2 = val.CenterPosition - owner.CenterPosition;
					float num2 = Vector3.Angle(((Component)owner).transform.forward, val2) * 0.13f + ((Vector3)(ref val2)).magnitude;
					if (num2 < num)
					{
						result = val;
						num = num2;
					}
				}
			}
			return result;
		}

		internal static bool Valid(Character owner, Character target)
		{
			//IL_003b: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || (Object)(object)target == (Object)(object)owner || !target.Alive || target.Invincible || target.IsLocalPlayer || !owner.TargetingSystem.IsTargetable(target))
			{
				return false;
			}
			Vector3 val = target.CenterPosition - owner.CenterPosition;
			if (((Vector3)(ref val)).sqrMagnitude <= 225f && Vector3.Angle(((Component)owner).transform.forward, val) <= 55f)
			{
				return !Physics.Linecast(owner.CenterPosition, target.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			}
			return false;
		}

		internal static Vector3 Ground(Character target)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(((Component)target).transform.position + Vector3.up * 1.8f, Vector3.down, ref val, 4f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				return ((Component)target).transform.position;
			}
			return ((RaycastHit)(ref val)).point;
		}
	}
	internal sealed class MarkTimeline
	{
		internal const float CastAt = 1f / 39f;

		internal const float ReleaseAt = 7f / 39f;

		private float progress;

		private bool released;

		private bool cancelled;

		internal bool Started
		{
			get
			{
				if (!cancelled)
				{
					return progress >= 1f / 39f;
				}
				return false;
			}
		}

		internal void Observe(float value)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, value);
			}
		}

		internal bool TryRelease()
		{
			if (cancelled || released || progress < 7f / 39f)
			{
				return false;
			}
			released = true;
			return true;
		}

		internal void Cancel()
		{
			cancelled = true;
		}
	}
	internal static class MarkVisual
	{
		private static Material glyph;

		private static Material blade;

		private static Texture2D iconTexture;

		private static Sprite icon;

		internal static void Ensure()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)glyph != (Object)null))
			{
				Shader obj = Shader.Find("Legacy Shaders/Particles/Alpha Blended");
				if ((Object)(object)obj == (Object)null)
				{
					throw new InvalidOperationException("Alpha-blended mark shader unavailable");
				}
				glyph = new Material(obj)
				{
					name = "Carrasco_Glifo"
				};
				glyph.SetColor("_TintColor", Color.white);
				blade = new Material(obj)
				{
					name = "Carrasco_Lamina"
				};
				blade.SetColor("_TintColor", Color.white);
			}
		}

		private static LineRenderer Line(Transform parent, string name, Material material, float width)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			((Renderer)obj).sharedMaterial = material;
			obj.useWorldSpace = false;
			obj.widthMultiplier = width;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.48f, 0.27f, 0.85f, 0.78f);
			obj.endColor = val2;
			obj.startColor = val2;
			obj.numCornerVertices = 2;
			obj.numCapVertices = 2;
			return obj;
		}

		internal static void Ring(Transform root)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			root.position += Vector3.up * 0.12f;
			for (int i = 0; i < 3; i++)
			{
				LineRenderer val = Line(root, "Carrasco_AnelExterno", glyph, 0.03f);
				Vector3[] array = (Vector3[])(object)new Vector3[25];
				for (int j = 0; j < array.Length; j++)
				{
					float num = ((float)(i * 120 + 7) + (float)j * 106f / 24f) * ((float)Math.PI / 180f);
					array[j] = new Vector3(Mathf.Cos(num) * 1.19f, 0f, Mathf.Sin(num) * 1.19f);
				}
				val.positionCount = array.Length;
				val.SetPositions(array);
			}
			LineRenderer val2 = Line(root, "Carrasco_AnelInterno", glyph, 0.017f);
			Vector3[] array2 = (Vector3[])(object)new Vector3[65];
			for (int k = 0; k < array2.Length; k++)
			{
				float num2 = (float)(k * 2) * (float)Math.PI / 64f;
				array2[k] = new Vector3(Mathf.Cos(num2) * 0.71f, 0.008f, Mathf.Sin(num2) * 0.71f);
			}
			val2.positionCount = array2.Length;
			val2.SetPositions(array2);
			for (int l = 0; l < 3; l++)
			{
				float num3 = (float)(l * 120 + 30) * ((float)Math.PI / 180f);
				LineRenderer obj = Line(root, "Carrasco_Runa", glyph, 0.025f);
				obj.positionCount = 4;
				obj.SetPositions((Vector3[])(object)new Vector3[4]
				{
					new Vector3(Mathf.Cos(num3) * 0.82f, 0.012f, Mathf.Sin(num3) * 0.82f),
					new Vector3(Mathf.Cos(num3 - 0.18f) * 1.02f, 0.012f, Mathf.Sin(num3 - 0.18f) * 1.02f),
					new Vector3(Mathf.Cos(num3 + 0.18f) * 1.02f, 0.012f, Mathf.Sin(num3 + 0.18f) * 1.02f),
					new Vector3(Mathf.Cos(num3) * 0.82f, 0.012f, Mathf.Sin(num3) * 0.82f)
				});
			}
		}

		internal static void Slash(Vector3 point, int index)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			GameObject val = new GameObject("Carrasco_Corte_" + (index + 1));
			val.transform.position = point + Vector3.up * 1.05f;
			LineRenderer val2 = Line(val.transform, "Lamina_Espectral", blade, 0.36f);
			val2.positionCount = 4;
			val2.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[4]
			{
				new Keyframe(0f, 0.25f),
				new Keyframe(0.14f, 0.9f),
				new Keyframe(0.7f, 0.55f),
				new Keyframe(1f, 0f)
			});
			val2.startColor = new Color(0.36f, 0.5f, 0.92f, 0.78f);
			val2.endColor = new Color(0.77f, 0.88f, 1f, 0.92f);
			val.AddComponent<MarkSlash>().Bind(val2, index);
		}

		internal static Sprite Icon()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: 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_012a: 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)
			if ((Object)(object)icon != (Object)null)
			{
				return icon;
			}
			iconTexture = new Texture2D(64, 64, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = (float)j - 31.5f;
					float num2 = (float)i - 31.5f;
					bool flag = Mathf.Abs(Mathf.Sqrt(num * num + num2 * num2) - 23f) < 1.6f;
					bool flag2 = Mathf.Abs(num + num2 * 0.4f) < 2.2f && num2 > -13f && num2 < 18f;
					bool flag3 = Mathf.Abs(num + num2 * 0.4f) < (18f - num2) * 0.15f && num2 >= 14f && num2 < 27f;
					bool flag4 = Mathf.Abs(num2 + 14f) < 1.5f && Mathf.Abs(num) < 10f;
					array[i * 64 + j] = (Color)(flag ? new Color(0.55f, 0.3f, 0.85f, 1f) : ((flag2 || flag3 || flag4) ? new Color(0.94f, 0.79f, 1f, 1f) : Color.clear));
				}
			}
			iconTexture.SetPixels(array);
			iconTexture.Apply(false, true);
			icon = Sprite.Create(iconTexture, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
			return icon;
		}

		internal static void Sound(Sounds sound, Vector3 point)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GlobalAudioManager audioManager = Global.AudioManager;
				if (audioManager != null)
				{
					audioManager.PlaySoundAtPosition(sound, point, 0f, 1f, 1f, 1f, 1f);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[MarcaCarrasco] AUDIO:" + ex.Message));
			}
		}

		internal static void Release()
		{
			if ((Object)(object)icon != (Object)null)
			{
				Object.Destroy((Object)(object)icon);
			}
			icon = null;
			if ((Object)(object)iconTexture != (Object)null)
			{
				Object.Destroy((Object)(object)iconTexture);
			}
			iconTexture = null;
			if ((Object)(object)glyph != (Object)null)
			{
				Object.Destroy((Object)(object)glyph);
			}
			glyph = null;
			if ((Object)(object)blade != (Object)null)
			{
				Object.Destroy((Object)(object)blade);
			}
			blade = null;
		}
	}
	public sealed class MarkSlash : MonoBehaviour
	{
		private LineRenderer line;

		private int index;

		private float age;

		internal void Bind(LineRenderer value, int number)
		{
			line = value;
			index = number;
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if (instance == null || !instance.IsGameplayPaused)
			{
				age += Time.deltaTime;
				Sample(age);
				if (age > 0.33f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		internal void Sample(float elapsed)
		{
			//IL_0052: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(elapsed / 0.27f);
			float num2 = (float)(index * 120 + 30) * ((float)Math.PI / 180f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2));
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(0f - Mathf.Sin(num2), 0f, Mathf.Cos(num2));
			Vector3 val3 = val * 2.05f + Vector3.up * 0.95f;
			Vector3 val4 = Vector3.Lerp(val3, -val * 0.55f + Vector3.down * 0.48f, num);
			line.SetPositions((Vector3[])(object)new Vector3[4]
			{
				val3,
				Vector3.Lerp(val3, val4, 0.16f) + val2 * 0.11f,
				Vector3.Lerp(val3, val4, 0.65f) + val2 * 0.16f,
				val4
			});
			line.widthMultiplier = 0.4f * (1f - num * 0.58f);
		}
	}
	[BepInPlugin("codex.outward.marca.carrasco", "Codex - Marca do Carrasco", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.marca.carrasco";

		public const int SkillId = 9106970;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = MarkVisual.Icon();
			patches = new Harmony("codex.outward.marca.carrasco");
			patches.PatchAll(typeof(Plugin).Assembly);
			SL_Item.AddOnInstanceStartListener(9106970, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[MarcaCarrasco] 1.0.1;treinador;external sword mark;three delayed spectral blades;PENDING USER");
		}

		private void Build()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				MarkClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				MarkVisual.Ensure();
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106970) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106970);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106970;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Marca do Carrasco";
				((SL_Item)val2).Description = "Marca o chao sob um inimigo a ate 15m. Apos 2s, tres laminas espectrais atingem o ponto marcado em sequencia. Saia da area para escapar. Cada corte causa 35 dano etereo e 12 impacto em 1,6m.30 vigor,45s recarga. Requer espada.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 30f;
				((SL_Skill)val2).Cooldown = 45f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[2]
				{
					default(WeaponType),
					(WeaponType)51
				};
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[MarcaCarrasco] PRONTO:9106970;Marca do Carrasco;Human=True;3 delayed slashes;30vigor/45s");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[MarcaCarrasco] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106970)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			MarkMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								MarkMotion markMotion = ((Component)value).GetComponent<MarkMotion>();
								if ((Object)(object)markMotion == (Object)null)
								{
									try
									{
										markMotion = ((Component)value).gameObject.AddComponent<MarkMotion>();
										markMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)markMotion != (Object)null)
										{
											Object.Destroy((Object)(object)markMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[MarcaCarrasco] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = markMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			MarkMotion[] array = Object.FindObjectsOfType<MarkMotion>();
			foreach (MarkMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			MarkField[] array2 = Object.FindObjectsOfType<MarkField>();
			for (int i = 0; i < array2.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			}
			MarkSlash[] array3 = Object.FindObjectsOfType<MarkSlash>();
			for (int i = 0; i < array3.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array3[i]).gameObject);
			}
			Harmony obj2 = patches;
			if (obj2 != null)
			{
				obj2.UnpatchAll("codex.outward.marca.carrasco");
			}
			MarkClip.Dispose();
			MarkVisual.Release();
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106970)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<MarkMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			MarkMotion component = ((Component)__instance).GetComponent<MarkMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106970)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter != null)
				{
					((Component)ownerCharacter).GetComponent<MarkMotion>()?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<MarkMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				MarkMotion markMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<MarkMotion>() : null);
				if (((Item)__instance).ItemID == 9106970)
				{
					__result = markMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && markMotion != null && markMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			MarkMotion component = ((Component)__instance).GetComponent<MarkMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}

BepInEx/plugins/Codex_Missao_Mantimentos/CodexMissaoMantimentos.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Xml;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using SideLoader;
using SideLoader.SaveData;
using UnityEngine;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexMissaoMantimentos
{
	internal static class ArenaRecipients
	{
		internal static bool IsRecipient(string uid)
		{
			if (!(uid == "codex.character.arena.kael.sol"))
			{
				return uid == "codex.character.arena.nara.medica";
			}
			return true;
		}

		internal static Vector3 Position(string uid)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3((float)((uid == "codex.character.arena.kael.sol") ? (-33) : (-1)), 255f, 1814.7f);
		}

		internal static bool Ready(Character character)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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)
			string text = ((object)character.UID/*cast due to .constrained prefix*/).ToString();
			if (!IsRecipient(text))
			{
				return false;
			}
			ArenaRecipientHost arenaRecipientHost = ((Component)character).GetComponent<ArenaRecipientHost>() ?? ((Component)character).gameObject.AddComponent<ArenaRecipientHost>();
			if (arenaRecipientHost.Ready)
			{
				return true;
			}
			if ((Object)(object)((Component)character).GetComponentInChildren<CharacterVisuals>(true) == (Object)null || (Object)(object)character.Animator == (Object)null)
			{
				arenaRecipientHost.ReadyAfter = 0f;
				return false;
			}
			if (arenaRecipientHost.ReadyAfter == 0f)
			{
				arenaRecipientHost.ReadyAfter = Time.realtimeSinceStartup + 2f;
				return false;
			}
			if (Time.realtimeSinceStartup < arenaRecipientHost.ReadyAfter)
			{
				return false;
			}
			if (!TrySurface(Position(text), out var surface, out var support))
			{
				arenaRecipientHost.Wait("piso alto nativo ainda ausente");
				return false;
			}
			Collider[] array = Physics.OverlapCapsule(surface + Vector3.up * 0.8f, surface + Vector3.up * 1.8f, 0.65f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)support && (Object)(object)((Component)val).GetComponentInParent<Character>() != (Object)(object)character && !IsFloor(val))
				{
					arenaRecipientHost.Wait("corpo bloqueado por " + ((Object)val).name);
					return false;
				}
			}
			character.Teleport(surface + Vector3.up * 0.12f, Quaternion.Euler(0f, (float)((text == "codex.character.arena.kael.sol") ? 90 : 270), 0f));
			if (!AttachBaseDialogue(character, VillageLore.Get(text)))
			{
				return false;
			}
			CharacterVisuals componentInChildren = ((Component)character).GetComponentInChildren<CharacterVisuals>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)((Component)componentInChildren).transform != (Object)(object)((Component)character).transform && !arenaRecipientHost.VisualRaised)
			{
				Transform transform = ((Component)componentInChildren).transform;
				transform.localPosition += Vector3.up * 0.08f;
				arenaRecipientHost.VisualRaised = true;
			}
			arenaRecipientHost.Ready = true;
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogMessage((object)("[EntregasArena] NPC PRONTO uid=" + text + ";world=" + ((object)((Component)character).transform.position/*cast due to .constrained prefix*/).ToString() + ";piso=" + ((Object)support).name + ";foraR40combate"));
			}
			return true;
		}

		private static bool IsFloor(Collider collider)
		{
			if (!((Object)collider).name.StartsWith("Campo_Oeste_Setor_", StringComparison.Ordinal))
			{
				return ((Object)collider).name == "CampoMecanico_Arena_Piso";
			}
			return true;
		}

		internal static bool TrySurface(Vector3 position, out Vector3 surface, out Collider support)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			surface = position;
			support = null;
			RaycastHit[] array = Physics.RaycastAll(new Vector3(position.x, 280f, position.z), Vector3.down, 60f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && IsFloor(((RaycastHit)(ref val)).collider) && !(((RaycastHit)(ref val)).normal.y < 0.8f) && !(((RaycastHit)(ref val)).point.y <= 220f) && ((Object)(object)support == (Object)null || ((RaycastHit)(ref val)).point.y > surface.y))
				{
					surface = ((RaycastHit)(ref val)).point;
					support = ((RaycastHit)(ref val)).collider;
				}
			}
			return (Object)(object)support != (Object)null;
		}

		private static bool AttachBaseDialogue(Character character, LoreProfile profile)
		{
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			if (profile == null)
			{
				return false;
			}
			DialogueTreeController[] componentsInChildren = ((Component)character).GetComponentsInChildren<DialogueTreeController>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Transform val = ((Component)componentsInChildren[i]).transform;
				while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)character).transform)
				{
					if (((Object)val).name.StartsWith("Entregas_Arena_Dialogo_", StringComparison.Ordinal))
					{
						return true;
					}
					val = val.parent;
				}
			}
			GameObject val2 = Resources.Load<GameObject>("editor/templates/TrainerTemplate");
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val2);
			((Object)val3).name = "Entregas_Arena_Dialogo_" + profile.Uid;
			val3.transform.SetParent(((Component)character).transform, false);
			try
			{
				DialogueTreeController componentInChildren = val3.GetComponentInChildren<DialogueTreeController>(true);
				DialogueActor componentInChildren2 = val3.GetComponentInChildren<DialogueActor>(true);
				Graph val4 = (((Object)(object)componentInChildren == (Object)null) ? null : ((GraphOwner)componentInChildren).graph);
				if ((Object)(object)val4 == (Object)null || (Object)(object)componentInChildren2 == (Object)null)
				{
					throw new InvalidOperationException("TrainerTemplate incompleto.");
				}
				string name = character.Name;
				componentInChildren2.SetName(name);
				DialogueTree val5 = (DialogueTree)(object)((val4 is DialogueTree) ? val4 : null);
				List<ActorParameter> list = (((Object)(object)val5 == (Object)null) ? null : (At.GetField<DialogueTree>(val5, "_actorParameters") as List<ActorParameter>));
				if (list == null || list.Count == 0)
				{
					throw new InvalidOperationException("Actor do dialogo ausente.");
				}
				list[0].actor = (IDialogueActor)(object)componentInChildren2;
				list[0].name = name;
				val4.allNodes.Clear();
				StatementNodeExt val6 = val4.AddNode<StatementNodeExt>();
				val6.statement = new Statement(profile.Greeting);
				val6.SetActorName(name);
				MultipleChoiceNodeExt val7 = val4.AddNode<MultipleChoiceNodeExt>();
				val4.primeNode = (Node)(object)val6;
				val4.ConnectNodes((Node)(object)val6, (Node)(object)val7, -1, -1);
				string[] array = new string[3] { profile.Topic, profile.Personal, "Ate mais." };
				string[] array2 = new string[3] { profile.Answer, profile.Story, "Volte inteiro. Conversaremos aqui fora." };
				for (int j = 0; j < 3; j++)
				{
					val7.availableChoices.Add(new Choice(new Statement(array[j])));
					StatementNodeExt val8 = val4.AddNode<StatementNodeExt>();
					val8.SetActorName(name);
					val8.statement = new Statement(array2[j]);
					val4.ConnectNodes((Node)(object)val7, (Node)(object)val8, j, -1);
					if (j < 2)
					{
						val4.ConnectNodes((Node)(object)val8, (Node)(object)val7, -1, -1);
					}
				}
				val3.SetActive(true);
				return true;
			}
			catch
			{
				Object.Destroy((Object)(object)val3);
				throw;
			}
		}
	}
	internal sealed class ArenaRecipientHost : MonoBehaviour
	{
		internal bool Ready;

		internal bool VisualRaised;

		internal float ReadyAfter;

		private float _nextScan;

		private float _nextWarning;

		internal void Wait(string reason)
		{
			//IL_0043: 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)
			if (!(Time.unscaledTime < _nextWarning))
			{
				_nextWarning = Time.unscaledTime + 30f;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					Character component = ((Component)this).GetComponent<Character>();
					UID? val = ((component != null) ? new UID?(component.UID) : ((UID?)null));
					log.LogWarning((object)("[EntregasArena] NPC aguardando uid=" + (val.HasValue ? UID.op_Implicit(val.GetValueOrDefault()) : null) + ";" + reason));
				}
			}
		}

		private void Update()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextScan)
			{
				return;
			}
			_nextScan = Time.unscaledTime + 0.5f;
			bool enabled = false;
			Character[] array = Object.FindObjectsOfType<Character>();
			foreach (Character val in array)
			{
				if ((Object)(object)val != (Object)null && val.IsLocalPlayer && ((Component)val).transform.position.y > 220f)
				{
					Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
					if (((Vector3)(ref val2)).sqrMagnitude < 52900f)
					{
						enabled = true;
						break;
					}
				}
			}
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					val3.enabled = enabled;
				}
			}
		}
	}
	internal sealed class DeliverySpec
	{
		internal readonly string Key;

		internal readonly string Title;

		internal readonly string GiverUid;

		internal readonly string ReceiverUid;

		internal readonly string GiverName;

		internal readonly string ReceiverName;

		internal readonly string ItemName;

		internal readonly string RewardName;

		internal readonly string Offer;

		internal readonly string Thanks;

		internal readonly int ItemId;

		internal readonly int RewardItemId;

		internal int RewardQuantity
		{
			get
			{
				if (RewardItemId != 0)
				{
					return 1;
				}
				return 20;
			}
		}

		internal DeliverySpec(string key, string title, string giver, string receiver, string giverName, string receiverName, int itemId, string itemName, int rewardItemId, string rewardName, string offer, string thanks)
		{
			Key = key;
			Title = title;
			GiverUid = giver;
			ReceiverUid = receiver;
			GiverName = giverName;
			ReceiverName = receiverName;
			ItemId = itemId;
			ItemName = itemName;
			RewardItemId = rewardItemId;
			RewardName = rewardName;
			Offer = offer;
			Thanks = thanks;
		}

		internal bool Includes(string uid)
		{
			if (!(uid == GiverUid))
			{
				return uid == ReceiverUid;
			}
			return true;
		}

		internal QuestState NewState(DeliveryStage stage = DeliveryStage.NotStarted, int pendingBefore = -1)
		{
			return new QuestState(stage, pendingBefore, RewardQuantity);
		}
	}
	internal static class DeliveryCatalog
	{
		internal const string Original = "mantimentos_tomas_v1";

		internal const string Solar = "centelha_sol_v1";

		internal const string Medical = "socorro_arena_v1";

		internal const string Brena = "codex.character.aldeia.brena";

		internal const string Ivo = "codex.character.aldeia.ivo";

		internal const string Rui = "codex.character.aldeia.rui";

		internal const string Kael = "codex.character.arena.kael.sol";

		internal const string Nara = "codex.character.arena.nara.medica";

		internal static readonly DeliverySpec[] All = new DeliverySpec[3]
		{
			new DeliverySpec("mantimentos_tomas_v1", "Mantimentos para Tomas", "codex.character.aldeia.alma", "codex.character.aldeia.tomas", "Alma", "Tomas", 4100550, "racao de viagem", 0, "20 pratas", null, null),
			new DeliverySpec("centelha_sol_v1", "Uma centelha para o sol", "codex.character.aldeia.tomas", "codex.character.arena.kael.sol", "Tomas", "Kael, Artifice do Sol", 6400130, "pedra de mana", 3100200, "Armadura Kintsugi Branca (Legacy)", "Kael estuda o sol artificial da arena. Separei uma pedra de mana para ele comparar com o nucleo. Pode leva-la? Ele espera do lado de fora da entrada da arena, a oeste do portao.", "A pedra chegou intacta. O sol ilumina a arena, mas nao domina o Colosso da Fornalha. Guarde esta armadura dos antigos artifices; voce fez sua parte sem entrar no combate."),
			new DeliverySpec("socorro_arena_v1", "Socorro antes da fornalha", "codex.character.aldeia.brena", "codex.character.arena.nara.medica", "Brena", "Nara, Medica da Arena", 4400010, "bandagem", 3100190, "Armadura Mestre Kazite (Legacy)", "Nara cuida de quem volta ferido da arena. Preparei uma bandagem para ela. Pode levar? Ela esta fora da entrada da arena, a leste do portao. Nao precisa enfrentar ninguem.", "Obrigada. As torretas e o Colosso nao distinguem coragem de imprudencia. Esta armadura foi deixada por um antigo guarda Kazite; use-a para voltar inteiro.")
		};

		internal static DeliverySpec Get(string key)
		{
			return Array.Find(All, (DeliverySpec s) => s.Key == key) ?? throw new ArgumentException("Missao desconhecida: " + key);
		}
	}
	public sealed class ExtraDeliverySave
	{
		public string Key;

		public int Stage = -1;

		public int PendingBefore = -1;
	}
	public sealed class DeliverySave : PlayerSaveExtension
	{
		public string Mission;

		public int Version = -1;

		public int Stage = -1;

		public int PendingBefore = -1;

		public ExtraDeliverySave[] Extras;

		internal const string Key = "mantimentos_tomas_v1";

		internal void Validate()
		{
			if (Mission != "mantimentos_tomas_v1" || (Version != 1 && Version != 2 && Version != 3) || !QuestState.Valid(Stage) || (Version == 1 && Stage > 3) || (QuestState.IsPending((DeliveryStage)Stage) && PendingBefore < 0))
			{
				throw new InvalidDataException("Progresso de Mantimentos invalido;nao reiniciei a missao.");
			}
			if (Version < 3 && Extras != null)
			{
				throw new InvalidDataException("Missoes extras em schema antigo.");
			}
			if (Version != 3)
			{
				return;
			}
			if (Extras == null || Extras.Length != 2)
			{
				throw new InvalidDataException("Missoes extras ausentes;nao reiniciei.");
			}
			HashSet<string> hashSet = new HashSet<string>();
			ExtraDeliverySave[] extras = Extras;
			foreach (ExtraDeliverySave extraDeliverySave in extras)
			{
				if (extraDeliverySave == null || (extraDeliverySave.Key != "centelha_sol_v1" && extraDeliverySave.Key != "socorro_arena_v1") || !hashSet.Add(extraDeliverySave.Key) || !QuestState.Valid(extraDeliverySave.Stage) || (QuestState.IsPending((DeliveryStage)extraDeliverySave.Stage) && extraDeliverySave.PendingBefore < 0))
				{
					throw new InvalidDataException("Progresso de entrega extra invalido.");
				}
			}
		}

		public override void Save(Character character, bool isWorldHost)
		{
			QuestMemory questMemory = QuestMemory.Get(character);
			QuestService.Poll(character, questMemory);
			Mission = "mantimentos_tomas_v1";
			Version = 3;
			Stage = (int)questMemory.State.Stage;
			PendingBefore = questMemory.State.PendingBefore;
			Extras = new ExtraDeliverySave[2];
			for (int i = 1; i < DeliveryCatalog.All.Length; i++)
			{
				DeliverySpec deliverySpec = DeliveryCatalog.All[i];
				QuestState state = questMemory.GetState(deliverySpec.Key);
				Extras[i - 1] = new ExtraDeliverySave
				{
					Key = deliverySpec.Key,
					Stage = (int)state.Stage,
					PendingBefore = state.PendingBefore
				};
			}
			questMemory.Dirty = false;
		}

		public override void ApplyLoadedSave(Character character, bool isWorldHost)
		{
			Validate();
			QuestMemory questMemory = QuestMemory.Component(character);
			if (questMemory.Dirty)
			{
				return;
			}
			if (!questMemory.Loaded || QuestState.Rank(questMemory.State.Stage) <= QuestState.Rank((DeliveryStage)Stage))
			{
				questMemory.State = new QuestState((DeliveryStage)Stage, PendingBefore);
			}
			if (Extras != null)
			{
				ExtraDeliverySave[] extras = Extras;
				foreach (ExtraDeliverySave extraDeliverySave in extras)
				{
					QuestState state = questMemory.GetState(extraDeliverySave.Key);
					if (!questMemory.Loaded || QuestState.Rank(state.Stage) <= QuestState.Rank((DeliveryStage)extraDeliverySave.Stage))
					{
						questMemory.ExtraStates[extraDeliverySave.Key] = DeliveryCatalog.Get(extraDeliverySave.Key).NewState((DeliveryStage)extraDeliverySave.Stage, extraDeliverySave.PendingBefore);
					}
				}
			}
			questMemory.Loaded = true;
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogMessage((object)("[Mantimentos] LOAD uid=" + questMemory.PlayerUid + ";stage=" + questMemory.State.Stage));
			}
		}
	}
	internal sealed class QuestMemory : MonoBehaviour
	{
		internal string PlayerUid;

		internal bool Loaded;

		internal bool Dirty;

		internal QuestState State;

		internal readonly Dictionary<string, QuestState> ExtraStates = new Dictionary<string, QuestState>();

		private bool _confirmationErrorLogged;

		internal QuestState GetState(string key)
		{
			if (key == "mantimentos_tomas_v1")
			{
				return State;
			}
			if (!ExtraStates.TryGetValue(key, out var value))
			{
				value = DeliveryCatalog.Get(key).NewState();
				ExtraStates.Add(key, value);
			}
			return value;
		}

		private void Update()
		{
			try
			{
				if (Loaded && State != null)
				{
					QuestService.Poll(((Component)this).GetComponent<Character>(), this);
				}
				_confirmationErrorLogged = false;
			}
			catch (Exception ex)
			{
				if (!_confirmationErrorLogged)
				{
					_confirmationErrorLogged = true;
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogError((object)("[Mantimentos] Confirmacao pendente preservada: " + ex));
					}
				}
			}
		}

		internal static QuestMemory Component(Character player)
		{
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || string.IsNullOrWhiteSpace(((object)player.UID/*cast due to .constrained prefix*/).ToString()))
			{
				throw new InvalidOperationException("Personagem sem UID pronto.");
			}
			QuestMemory questMemory = ((Component)player).GetComponent<QuestMemory>() ?? ((Component)player).gameObject.AddComponent<QuestMemory>();
			string text = ((object)player.UID/*cast due to .constrained prefix*/).ToString();
			if (questMemory.PlayerUid != text)
			{
				questMemory.PlayerUid = text;
				questMemory.Loaded = false;
				questMemory.Dirty = false;
				questMemory.State = new QuestState();
				questMemory.ExtraStates.Clear();
			}
			return questMemory;
		}

		internal static QuestMemory Get(Character player)
		{
			//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_0037: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			QuestMemory questMemory = Component(player);
			if (questMemory.Loaded)
			{
				return questMemory;
			}
			string saveFilePath = PlayerSaveExtension.GetSaveFilePath<DeliverySave>(questMemory.PlayerUid);
			if (File.Exists(saveFilePath))
			{
				XmlReader val = XmlReader.Create(saveFilePath, new XmlReaderSettings
				{
					DtdProcessing = (DtdProcessing)0
				});
				try
				{
					((PlayerSaveExtension)(DeliverySave)new XmlSerializer(typeof(DeliverySave)).Deserialize(val)).ApplyLoadedSave(player, false);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			questMemory.Loaded = true;
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogMessage((object)("[Mantimentos] READY uid=" + questMemory.PlayerUid + ";stage=" + questMemory.State.Stage.ToString() + ";extras=" + questMemory.ExtraStates.Count));
			}
			return questMemory;
		}
	}
	internal static class DialogueAddon
	{
		internal static bool Attach(Graph graph, string uid, string speaker, string mission = "mantimentos_tomas_v1")
		{
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Expected O, but got Unknown
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Expected O, but got Unknown
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected O, but got Unknown
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Expected O, but got Unknown
			if (!(graph is DialogueTreeExt) || graph.isRunning)
			{
				return false;
			}
			DeliverySpec deliverySpec = DeliveryCatalog.Get(mission);
			if (!deliverySpec.Includes(uid))
			{
				return false;
			}
			foreach (Node allNode in graph.allNodes)
			{
				if (allNode is DeliveryNode deliveryNode && deliveryNode.NpcUid == uid && deliveryNode.Mission == mission)
				{
					return true;
				}
			}
			Node? obj = graph.allNodes.Find((Node n) => n is MultipleChoiceNodeExt);
			MultipleChoiceNodeExt val = (MultipleChoiceNodeExt)(object)((obj is MultipleChoiceNodeExt) ? obj : null);
			if (val == null || val.availableChoices.Count != ((Node)val).outConnections.Count)
			{
				return false;
			}
			int count = val.availableChoices.Count;
			List<Node> list = new List<Node>();
			try
			{
				bool flag = uid == deliverySpec.GiverUid;
				DeliveryNode deliveryNode2 = graph.AddNode<DeliveryNode>();
				list.Add((Node)(object)deliveryNode2);
				deliveryNode2.NpcUid = uid;
				deliveryNode2.Giver = flag;
				deliveryNode2.Mission = mission;
				StatementNodeExt val2 = graph.AddNode<StatementNodeExt>();
				list.Add((Node)(object)val2);
				val2.SetActorName(speaker);
				val2.ContinueOnStatementFinished = true;
				deliveryNode2.Output = val2;
				MultipleChoiceNodeExt val3 = graph.AddNode<MultipleChoiceNodeExt>();
				list.Add((Node)(object)val3);
				DeliveryNode deliveryNode3 = graph.AddNode<DeliveryNode>();
				list.Add((Node)(object)deliveryNode3);
				deliveryNode3.NpcUid = uid;
				deliveryNode3.Giver = flag;
				deliveryNode3.Act = true;
				deliveryNode3.Mission = mission;
				StatementNodeExt val4 = graph.AddNode<StatementNodeExt>();
				list.Add((Node)(object)val4);
				val4.SetActorName(speaker);
				val4.ContinueOnStatementFinished = true;
				deliveryNode3.Output = val4;
				graph.ConnectNodes((Node)(object)deliveryNode2, (Node)(object)val2, -1, -1);
				graph.ConnectNodes((Node)(object)val2, (Node)(object)val3, -1, -1);
				val3.availableChoices.Add(new Choice(new Statement(flag ? ("Aceitar e pegar 1 " + ((mission == "mantimentos_tomas_v1") ? "racao" : deliverySpec.ItemName)) : "Entregar item / receber recompensa")));
				graph.ConnectNodes((Node)(object)val3, (Node)(object)deliveryNode3, 0, -1);
				val3.availableChoices.Add(new Choice(new Statement("Voltar a conversa.")));
				graph.ConnectNodes((Node)(object)val3, (Node)(object)val, 1, -1);
				graph.ConnectNodes((Node)(object)deliveryNode3, (Node)(object)val4, -1, -1);
				graph.ConnectNodes((Node)(object)val4, (Node)(object)val, -1, -1);
				val.availableChoices.Add(new Choice(new Statement("Missao: " + deliverySpec.Title)));
				graph.ConnectNodes((Node)(object)val, (Node)(object)deliveryNode2, count, -1);
				return true;
			}
			catch
			{
				for (int num = list.Count - 1; num >= 0; num--)
				{
					graph.RemoveNode(list[num], true, false);
				}
				while (val.availableChoices.Count > count)
				{
					val.availableChoices.RemoveAt(val.availableChoices.Count - 1);
				}
				throw;
			}
		}
	}
	public sealed class DeliveryNode : DTNode
	{
		public string NpcUid;

		public string Mission = "mantimentos_tomas_v1";

		public bool Giver;

		public bool Act;

		public StatementNodeExt Output;

		public override bool requireActorSelection => false;

		protected override Status OnExecute(Component agent, IBlackboard bb)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			DialogueTree dLGTree = ((DTNode)this).DLGTree;
			DialogueTreeExt val = (DialogueTreeExt)(object)((dLGTree is DialogueTreeExt) ? dLGTree : null);
			Character player = (((Object)(object)val == (Object)null) ? null : val.Instigator);
			if (Output != null)
			{
				DeliverySpec deliverySpec = DeliveryCatalog.Get(Mission);
				if (deliverySpec.Includes(NpcUid) && Giver == (NpcUid == deliverySpec.GiverUid))
				{
					Output.statement = new Statement(QuestService.Run(player, Giver, Act, Mission));
					((DTNode)this).DLGTree.Continue(0);
					return (Status)1;
				}
				return (Status)4;
			}
			return (Status)4;
		}
	}
	[BepInPlugin("codex.outward.missao.mantimentos", "Codex - Mantimentos para Tomas", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private float _nextScan;

		private float _nextError;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[Mantimentos] 1.1.1;3 entregas independentes;2 recompensasLegacy;Kael/Nara fora da arena;rotas sem portal verde;schema3 compativel com1/2.");
		}

		private void Update()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextScan)
			{
				return;
			}
			_nextScan = Time.unscaledTime + 2f;
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "CierzoTutorial")
			{
				return;
			}
			Character[] array = Object.FindObjectsOfType<Character>();
			foreach (Character val in array)
			{
				if ((Object)(object)val == (Object)null || !val.Initialized)
				{
					continue;
				}
				string text = ((object)val.UID/*cast due to .constrained prefix*/).ToString();
				bool flag = VillageLore.Get(text) != null;
				DeliverySpec[] all = DeliveryCatalog.All;
				for (int j = 0; j < all.Length; j++)
				{
					if (all[j].Includes(text))
					{
						flag = true;
					}
				}
				if (!flag)
				{
					continue;
				}
				bool flag2 = false;
				MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
				foreach (MonoBehaviour val2 in components)
				{
					if ((Object)(object)val2 != (Object)null && ((object)val2).GetType().FullName == "CodexSalaPretoTeste.VillageDialogueHost")
					{
						flag2 = true;
						break;
					}
				}
				if (ArenaRecipients.IsRecipient(text))
				{
					try
					{
						flag2 = ArenaRecipients.Ready(val);
					}
					catch (Exception ex)
					{
						if (Time.unscaledTime >= _nextError)
						{
							_nextError = Time.unscaledTime + 30f;
							((BaseUnityPlugin)this).Logger.LogError((object)("[EntregasArena] NPC sera repetido: " + ex));
						}
					}
				}
				if (!flag2)
				{
					continue;
				}
				DialogueTreeController[] componentsInChildren = ((Component)val).GetComponentsInChildren<DialogueTreeController>(true);
				foreach (DialogueTreeController val3 in componentsInChildren)
				{
					if (!IsVillageController(((Component)val3).transform, ((Component)val).transform))
					{
						continue;
					}
					try
					{
						Graph graph = ((GraphOwner)val3).graph;
						if ((Object)(object)graph == (Object)null || graph.isRunning)
						{
							continue;
						}
						DialogueTree val4 = (DialogueTree)(object)((graph is DialogueTree) ? graph : null);
						string speaker = (((Object)(object)val4 != (Object)null && val4.actorParameters.Count > 0) ? val4.actorParameters[0].name : val.Name);
						if (VillageLore.Apply(graph, text))
						{
							((BaseUnityPlugin)this).Logger.LogMessage((object)("[EntregasArena] HISTORIA PRONTA npc=" + text + ";somente falas/rotulos;conexoes preservadas."));
						}
						all = DeliveryCatalog.All;
						foreach (DeliverySpec deliverySpec in all)
						{
							if (!deliverySpec.Includes(text))
							{
								continue;
							}
							bool flag3 = false;
							foreach (Node allNode in graph.allNodes)
							{
								if (allNode is DeliveryNode deliveryNode && deliveryNode.Mission == deliverySpec.Key)
								{
									flag3 = true;
									break;
								}
							}
							if (!flag3 && DialogueAddon.Attach(graph, text, speaker, deliverySpec.Key))
							{
								((BaseUnityPlugin)this).Logger.LogMessage((object)("[Mantimentos] DIALOGO PRONTO npc=" + text + ";mission=" + deliverySpec.Key + ";opcao extra."));
							}
						}
					}
					catch (Exception ex2)
					{
						if (Time.unscaledTime >= _nextError)
						{
							_nextError = Time.unscaledTime + 30f;
							((BaseUnityPlugin)this).Logger.LogError((object)("[Mantimentos] Dialogo sera repetido: " + ex2));
						}
					}
				}
			}
		}

		private static bool IsVillageController(Transform item, Transform character)
		{
			Transform val = item;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)character)
			{
				if (((Object)val).name.StartsWith("Aldeia_Dialogo_", StringComparison.Ordinal) || ((Object)val).name.StartsWith("Entregas_Arena_Dialogo_", StringComparison.Ordinal))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private void OnDestroy()
		{
			if (Log == ((BaseUnityPlugin)this).Logger)
			{
				Log = null;
			}
		}
	}
	internal static class QuestService
	{
		private sealed class NativeInventory : IDeliveryInventory
		{
			private readonly Character _player;

			private readonly DeliverySpec _spec;

			public int DeliveryItemCount => _player.Inventory.ItemCount(_spec.ItemId);

			public int RewardCount
			{
				get
				{
					if (_spec.RewardItemId != 0)
					{
						return _player.Inventory.ItemCount(_spec.RewardItemId);
					}
					return _player.Inventory.ContainedSilver;
				}
			}

			internal NativeInventory(Character player, DeliverySpec spec)
			{
				_player = player;
				_spec = spec;
			}

			public void GiveItem()
			{
				ChangeRation(1);
			}

			public void RemoveRation()
			{
				ChangeRation(-1);
			}

			private void ChangeRation(int delta)
			{
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				int deliveryItemCount = DeliveryItemCount;
				try
				{
					if (delta > 0)
					{
						_player.Inventory.ReceiveItemReward(_spec.ItemId, 1, false);
					}
					else
					{
						_player.Inventory.RemoveItem(_spec.ItemId, 1);
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("[Mantimentos] API de item/notificacao: " + ex));
					}
				}
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					string[] obj = new string[13]
					{
						"[Mantimentos] ITEM uid=",
						UID.op_Implicit(_player.UID),
						";mission=",
						_spec.Key,
						";item=",
						null,
						null,
						null,
						null,
						null,
						null,
						null,
						null
					};
					int itemId = _spec.ItemId;
					obj[5] = itemId.ToString();
					obj[6] = ";delta=";
					obj[7] = delta.ToString();
					obj[8] = ";before=";
					obj[9] = deliveryItemCount.ToString();
					obj[10] = ";immediate=";
					obj[11] = DeliveryItemCount.ToString();
					obj[12] = ";confirmation=next-update";
					log2.LogMessage((object)string.Concat(obj));
				}
			}

			public void GiveReward()
			{
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				int rewardCount = RewardCount;
				try
				{
					if (_spec.RewardItemId == 0)
					{
						_player.Inventory.ReceiveMoneyReward(20);
					}
					else
					{
						_player.Inventory.ReceiveItemReward(_spec.RewardItemId, 1, false);
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("[Mantimentos] API de recompensa/notificacao: " + ex));
					}
				}
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					string[] obj = new string[11]
					{
						"[Mantimentos] REWARD uid=",
						UID.op_Implicit(_player.UID),
						";mission=",
						_spec.Key,
						";item=",
						null,
						null,
						null,
						null,
						null,
						null
					};
					int rewardItemId = _spec.RewardItemId;
					obj[5] = rewardItemId.ToString();
					obj[6] = ";before=";
					obj[7] = rewardCount.ToString();
					obj[8] = ";immediate=";
					obj[9] = RewardCount.ToString();
					obj[10] = ";confirmation=next-update";
					log2.LogMessage((object)string.Concat(obj));
				}
			}
		}

		internal const string Alma = "codex.character.aldeia.alma";

		internal const string Tomas = "codex.character.aldeia.tomas";

		internal static string Run(Character player, bool giver, bool act, string mission = "mantimentos_tomas_v1")
		{
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || !player.IsLocalPlayer || !player.IsPhotonPlayerLocal || !player.Alive || !player.Initialized || (Object)(object)player.Inventory == (Object)null)
			{
				return "Nao consegui identificar quem esta conversando. Tente falar comigo novamente.";
			}
			QuestMemory questMemory = null;
			QuestState questState = null;
			DeliveryStage deliveryStage = DeliveryStage.NotStarted;
			try
			{
				DeliverySpec deliverySpec = DeliveryCatalog.Get(mission);
				questMemory = QuestMemory.Get(player);
				questState = questMemory.GetState(mission);
				deliveryStage = questState.Stage;
				Poll(player, questMemory);
				if (!act)
				{
					return (mission == "mantimentos_tomas_v1") ? Describe(questState.Stage, giver) : DescribeExtra(deliverySpec, questState.Stage, giver);
				}
				DeliverySpec[] all = DeliveryCatalog.All;
				foreach (DeliverySpec deliverySpec2 in all)
				{
					if (deliverySpec2.Key != mission && QuestState.IsPending(questMemory.GetState(deliverySpec2.Key).Stage))
					{
						return "Estou conferindo outra entrega. Aguarde um instante e fale comigo novamente.";
					}
				}
				if (ResourcesPrefabManager.Instance == null || (Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(deliverySpec.ItemId) == (Object)null || (deliverySpec.RewardItemId != 0 && (Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(deliverySpec.RewardItemId) == (Object)null))
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						string[] obj = new string[7] { "[Mantimentos] PREFAB AUSENTE mission=", mission, ";item=", null, null, null, null };
						int i = deliverySpec.ItemId;
						obj[3] = i.ToString();
						obj[4] = ";reward=";
						i = deliverySpec.RewardItemId;
						obj[5] = i.ToString();
						obj[6] = ";nenhuma mutacao enviada";
						log.LogWarning((object)string.Concat(obj));
					}
					return "Os mantimentos ainda nao ficaram prontos. Volte em um instante.";
				}
				NativeInventory inventory = new NativeInventory(player, deliverySpec);
				Outcome result = (giver ? questState.Accept(inventory) : questState.Deliver(inventory));
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogMessage((object)("[Mantimentos] uid=" + UID.op_Implicit(player.UID) + ";mission=" + mission + ";npc=" + (giver ? deliverySpec.GiverName : deliverySpec.ReceiverName) + ";result=" + result.ToString() + ";stage=" + questState.Stage));
				}
				return (mission == "mantimentos_tomas_v1") ? Message(result) : ExtraMessage(deliverySpec, result);
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogError((object)("[Mantimentos] Interacao suspensa,progresso nao reiniciado: " + ex));
				}
				return "Nao consegui conferir sua entrega com seguranca. Seu progresso nao foi reiniciado; tente falar comigo novamente.";
			}
			finally
			{
				if ((Object)(object)questMemory != (Object)null && questState != null && questState.Stage != deliveryStage)
				{
					questMemory.Dirty = true;
				}
			}
		}

		internal static string Describe(DeliveryStage stage, bool giver)
		{
			if (QuestState.IsPending(stage))
			{
				if (stage != DeliveryStage.PaymentPending)
				{
					return "Estou conferindo os mantimentos na bolsa. Aguarde um instante e fale comigo novamente; nao vou cobrar nem entregar outra racao.";
				}
				return "Ja recebi os mantimentos e solicitei suas 20 pratas. Estou confirmando o pagamento; nao precisa trazer outra racao.";
			}
			switch (stage)
			{
			case DeliveryStage.Completed:
				if (!giver)
				{
					return "A entrega ja foi concluida e suas 20 pratas ja foram pagas. Obrigado!";
				}
				return "Tomas recebeu os mantimentos. Obrigada por ajudar nossa aldeia!";
			case DeliveryStage.RewardDue:
				if (!giver)
				{
					return "Ja recebi sua racao. Ainda devo 20 pratas; escolha receber a recompensa.";
				}
				return "A entrega esta feita. Fale com Tomas para receber suas 20 pratas.";
			case DeliveryStage.Accepted:
				if (!giver)
				{
					return "Alma avisou que voce traria uma racao de viagem. Entregue uma e eu lhe pagarei 20 pratas.";
				}
				return "Ja entreguei uma racao a voce. Leve uma racao de viagem para Tomas, o carpinteiro, aqui na aldeia.";
			default:
				if (!giver)
				{
					return "Alma esta separando meus mantimentos. Fale com ela primeiro para aceitar a entrega.";
				}
				return "Tomas esta ocupado consertando as casas. Pode levar uma racao de viagem para ele? Eu dou os mantimentos e ele lhe paga 20 pratas.";
			}
		}

		internal static void Poll(Character player, QuestMemory memory)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || !player.IsLocalPlayer || !player.IsPhotonPlayerLocal || !player.Initialized || (Object)(object)player.Inventory == (Object)null || !memory.Loaded)
			{
				return;
			}
			DeliverySpec[] all = DeliveryCatalog.All;
			foreach (DeliverySpec deliverySpec in all)
			{
				QuestState state = memory.GetState(deliverySpec.Key);
				if (!QuestState.IsPending(state.Stage))
				{
					continue;
				}
				DeliveryStage stage = state.Stage;
				state.Reconcile(new NativeInventory(player, deliverySpec));
				if (stage != state.Stage)
				{
					memory.Dirty = true;
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogMessage((object)("[Mantimentos] CONFIRM uid=" + UID.op_Implicit(player.UID) + ";mission=" + deliverySpec.Key + ";from=" + stage.ToString() + ";stage=" + state.Stage));
					}
				}
			}
		}

		private static string DescribeExtra(DeliverySpec spec, DeliveryStage stage, bool giver)
		{
			if (stage == DeliveryStage.Completed)
			{
				return "Esta entrega ja foi concluida. Sua recompensa, " + spec.RewardName + ", ja foi entregue.";
			}
			if (QuestState.IsPending(stage))
			{
				return "Estou confirmando o item na bolsa. Aguarde e fale comigo novamente; nao vou repetir o consumo nem a recompensa.";
			}
			switch (stage)
			{
			case DeliveryStage.RewardDue:
				return "Ja recebi o item. Escolha receber a recompensa: " + spec.RewardName + ". Nao precisa trazer outro.";
			case DeliveryStage.Accepted:
				if (!giver)
				{
					return "Voce aceitou a entrega com " + spec.GiverName + ". Traga 1 " + spec.ItemName + " na bolsa ou mochila. Recompensa: " + spec.RewardName + ".";
				}
				return "Ja entreguei 1 " + spec.ItemName + ". Procure " + spec.ReceiverName + " fora da entrada da arena, ao lado do portal verde.";
			default:
				if (!giver)
				{
					return "Fale com " + spec.GiverName + " em Vale Manso para aceitar a entrega de 1 " + spec.ItemName + ". Depois volte aqui. Recompensa: " + spec.RewardName + ".";
				}
				return spec.Offer + " Recompensa: " + spec.RewardName + ".";
			}
		}

		private static string ExtraMessage(DeliverySpec spec, Outcome result)
		{
			return result switch
			{
				Outcome.Accepted => "Aqui esta 1 " + spec.ItemName + ". Leve a " + spec.ReceiverName + ", ao lado de fora da entrada da arena. Recompensa: " + spec.RewardName + ".", 
				Outcome.AlreadyAccepted => "Voce ja aceitou. Procure " + spec.ReceiverName + ";nao vou entregar outro item gratuito.", 
				Outcome.NotAccepted => "Fale primeiro com " + spec.GiverName + " em Vale Manso e aceite esta entrega.", 
				Outcome.MissingRation => "Traga 1 " + spec.ItemName + " na bolsa ou mochila. Sua missao continua aceita.", 
				Outcome.Completed => spec.Thanks + " Recebeu: " + spec.RewardName + ". Entrega concluida.", 
				Outcome.AlreadyCompleted => "Esta entrega ja foi concluida;voce ja recebeu " + spec.RewardName + ". Nao ha outra recompensa.", 
				Outcome.RewardPending => "Recebi o item e solicitei " + spec.RewardName + ". Aguarde a confirmacao na bolsa;nao precisa entregar outro item.", 
				Outcome.Busy => "Estou confirmando a entrega. Aguarde um instante e fale comigo novamente.", 
				_ => "Nao consegui conferir o item. A entrega foi preservada.", 
			};
		}

		private static string Message(Outcome result)
		{
			return result switch
			{
				Outcome.Accepted => "Aqui esta uma racao de viagem. Leve-a para Tomas, o carpinteiro, nesta aldeia. Ele lhe pagara 20 pratas.", 
				Outcome.AlreadyAccepted => "Voce ja aceitou esta entrega. Nao ha outra racao gratuita; procure Tomas para terminar.", 
				Outcome.NotAccepted => "Fale com Alma primeiro e aceite a entrega dos mantimentos.", 
				Outcome.MissingRation => "Voce precisa trazer uma racao de viagem na bolsa ou mochila. A entrega continua pendente.", 
				Outcome.Completed => "Recebi os mantimentos! Aqui estao suas 20 pratas. Entrega concluida; muito obrigado.", 
				Outcome.AlreadyCompleted => "Esta entrega ja foi concluida. A recompensa nao pode ser recebida novamente.", 
				Outcome.RewardPending => "Ja recebi sua racao e solicitei suas 20 pratas. Aguarde a confirmacao e fale comigo novamente; nao precisa trazer outra racao.", 
				Outcome.Busy => "Estou conferindo a entrega. Aguarde um instante.", 
				_ => "Nao consegui movimentar o item. Confira sua bolsa e fale comigo novamente.", 
			};
		}
	}
	public enum DeliveryStage
	{
		NotStarted,
		Accepted,
		RewardDue,
		Completed,
		RationPending,
		RemovalPending,
		PaymentPending
	}
	internal enum Outcome
	{
		Accepted,
		AlreadyAccepted,
		NotAccepted,
		MissingRation,
		Completed,
		AlreadyCompleted,
		RewardPending,
		InventoryFailure,
		Busy
	}
	internal interface IDeliveryInventory
	{
		int DeliveryItemCount { get; }

		int RewardCount { get; }

		void GiveItem();

		void RemoveRation();

		void GiveReward();
	}
	internal sealed class QuestState
	{
		internal const int RationId = 4100550;

		internal const int Reward = 20;

		private bool _busy;

		private readonly int _rewardQuantity;

		internal DeliveryStage Stage { get; private set; }

		internal int PendingBefore { get; private set; }

		internal QuestState(DeliveryStage stage = DeliveryStage.NotStarted, int pendingBefore = -1, int rewardQuantity = 20)
		{
			if (!Valid((int)stage))
			{
				throw new ArgumentOutOfRangeException("stage");
			}
			if (IsPending(stage) && pendingBefore < 0)
			{
				throw new ArgumentOutOfRangeException("pendingBefore");
			}
			if (rewardQuantity <= 0)
			{
				throw new ArgumentOutOfRangeException("rewardQuantity");
			}
			_rewardQuantity = rewardQuantity;
			Stage = stage;
			PendingBefore = (IsPending(stage) ? pendingBefore : (-1));
		}

		internal static bool Valid(int stage)
		{
			if (stage >= 0)
			{
				return stage <= 6;
			}
			return false;
		}

		internal static bool IsPending(DeliveryStage stage)
		{
			if (stage != DeliveryStage.RationPending && stage != DeliveryStage.RemovalPending)
			{
				return stage == DeliveryStage.PaymentPending;
			}
			return true;
		}

		internal static int Rank(DeliveryStage stage)
		{
			return stage switch
			{
				DeliveryStage.RationPending => 1, 
				DeliveryStage.Accepted => 2, 
				DeliveryStage.RemovalPending => 3, 
				DeliveryStage.RewardDue => 4, 
				DeliveryStage.PaymentPending => 5, 
				DeliveryStage.Completed => 6, 
				_ => 0, 
			};
		}

		internal void Reconcile(IDeliveryInventory inventory)
		{
			if (!_busy)
			{
				Confirm(inventory);
			}
		}

		private void Confirm(IDeliveryInventory inventory)
		{
			if (Stage == DeliveryStage.RationPending && inventory.DeliveryItemCount > PendingBefore)
			{
				Stage = DeliveryStage.Accepted;
			}
			else if (Stage == DeliveryStage.RemovalPending && inventory.DeliveryItemCount < PendingBefore)
			{
				Stage = DeliveryStage.RewardDue;
			}
			else if (Stage == DeliveryStage.PaymentPending && inventory.RewardCount >= (long)PendingBefore + (long)_rewardQuantity)
			{
				Stage = DeliveryStage.Completed;
			}
			if (!IsPending(Stage))
			{
				PendingBefore = -1;
			}
		}

		private void Reserve(DeliveryStage stage, int before)
		{
			Stage = stage;
			PendingBefore = before;
		}

		internal Outcome Accept(IDeliveryInventory inventory)
		{
			if (_busy)
			{
				return Outcome.Busy;
			}
			Confirm(inventory);
			if (Stage == DeliveryStage.Completed)
			{
				return Outcome.AlreadyCompleted;
			}
			if (IsPending(Stage))
			{
				return Outcome.Busy;
			}
			if (Stage != DeliveryStage.NotStarted)
			{
				return Outcome.AlreadyAccepted;
			}
			_busy = true;
			try
			{
				Reserve(DeliveryStage.RationPending, inventory.DeliveryItemCount);
				inventory.GiveItem();
				Confirm(inventory);
				return (Stage != DeliveryStage.Accepted) ? Outcome.Busy : Outcome.Accepted;
			}
			finally
			{
				_busy = false;
			}
		}

		internal Outcome Deliver(IDeliveryInventory inventory)
		{
			if (_busy)
			{
				return Outcome.Busy;
			}
			Confirm(inventory);
			if (Stage == DeliveryStage.Completed)
			{
				return Outcome.AlreadyCompleted;
			}
			if (IsPending(Stage))
			{
				return Outcome.Busy;
			}
			if (Stage == DeliveryStage.NotStarted)
			{
				return Outcome.NotAccepted;
			}
			_busy = true;
			try
			{
				if (Stage == DeliveryStage.Accepted)
				{
					if (inventory.DeliveryItemCount <= 0)
					{
						return Outcome.MissingRation;
					}
					Reserve(DeliveryStage.RemovalPending, inventory.DeliveryItemCount);
					inventory.RemoveRation();
					Confirm(inventory);
					if (Stage == DeliveryStage.RemovalPending)
					{
						return Outcome.Busy;
					}
				}
				Reserve(DeliveryStage.PaymentPending, inventory.RewardCount);
				inventory.GiveReward();
				Confirm(inventory);
				return (Stage == DeliveryStage.Completed) ? Outcome.Completed : Outcome.RewardPending;
			}
			finally
			{
				_busy = false;
			}
		}
	}
	internal sealed class LoreProfile
	{
		internal readonly string Uid;

		internal readonly string Greeting;

		internal readonly string Topic;

		internal readonly string Answer;

		internal readonly string Personal;

		internal readonly string Story;

		internal LoreProfile(string uid, string greeting, string topic, string answer, string personal, string story)
		{
			Uid = uid;
			Greeting = greeting;
			Topic = topic;
			Answer = answer;
			Personal = personal;
			Story = story;
		}
	}
	internal static class VillageLore
	{
		internal static readonly LoreProfile[] All = new LoreProfile[6]
		{
			new LoreProfile("codex.character.aldeia.tomas", "Bem-vindo. Entre um telhado e outro, tambem conserto os suportes dos nossos postes.", "Quem mantem as luzes funcionando?", "Os postes guardam o caminho de Vale Manso quando anoitece. O sol artificial da arena e outro trabalho: Kael estuda seu nucleo. Separei uma pedra de mana para ele;se quiser ajudar,pergunte pela entrega.", "Por que ajudar a arena?", "Construir um lar nao basta se ninguem consegue voltar para ele. A luz ajuda os viajantes,mas nao detem o Colosso da Fornalha nem suas torretas. Prefiro reparar coisas do que contar os que faltam."),
			new LoreProfile("codex.character.aldeia.brena", "Voltou inteiro? Entao ainda temos tempo de cuidar de quem nao teve a mesma sorte.", "Ha feridos na arena?", "Nara atende os que voltam da Fornalha. As torretas queimam,a geada corta,e o Colosso nao se cansa facilmente. Separei uma bandagem para ela. A entrega termina fora da arena;nao precisa lutar.", "O frio ainda preocupa voce?", "O sol artificial ilumina a arena,nao toda esta regiao. Ainda colho plantas que resistem ao gelo. A luz pode enganar os olhos;um corpo ferido continua precisando de abrigo e cuidado."),
			new LoreProfile("codex.character.aldeia.ivo", "Voltei da estrada da Fornalha. Aquele sol fica aceso mesmo quando o resto do mundo escurece.", "O que encontrou na estrada?", "Mais adiante ficam as ruinas da Fenda. Muito alem delas, a arena tem paredes curvas e marcas de antigas maquinas. O caminho oeste e longo, mas os postes ajudam a encontrar a volta.", "Voce entrou na arena?", "Cheguei ate a entrada. Kael e Nara trabalham do lado de fora. Quando ouvi as engrenagens do Colosso,decidi que observar de longe tambem era uma forma de aprender."),
			new LoreProfile("codex.character.aldeia.rui", "Pode entrar. Enquanto eu estiver aqui,ninguem precisa enfrentar a noite sozinho.", "Como volto para a cidade de gelo?", "Saia por esta entrada e siga para leste. A abertura nos paredoes fica a cerca de cento e sessenta metros. Os postes ajudam depois que escurece.", "O que voce vigia agora?", "Viajantes vindos das ruinas e gente que acredita que o sol artificial venceu todos os perigos. A Fornalha continua la. Se for ate a arena, fale com os dois cuidadores antes de atravessar o portao."),
			new LoreProfile("codex.character.arena.kael.sol", "Aqui fora podemos conversar. La dentro,a Fornalha responde com ferro e fogo.", "O que e aquele sol?", "Um nucleo artificial suspenso acima da arena. Ele ilumina sem esperar a noite,mas nao controla as torretas. Estudo uma forma de entender sua luz. Tomas,em Vale Manso,separou uma pedra de mana para mim.", "Quem e o Colosso da Fornalha?", "Uma maquina de combate que guarda o centro. As torretas cobrem suas laterais,e seus golpes varrem quem chega sem preparo. Nao precisa enfrenta-lo para me entregar a pedra. Sou artifice,nao recrutador."),
			new LoreProfile("codex.character.arena.nara.medica", "Se veio ajudar,fique aqui fora. Se veio lutar,lembre-se de que eu nao consigo costurar imprudencia.", "Voce cuida dos feridos?", "Dos que conseguem sair. Brena,em Vale Manso,prepara bandagens para este posto. Se ela lhe confiar uma,entregue aqui. Tenho uma armadura de um antigo guarda Kazite para agradecer sua ajuda.", "A luz deixa a arena segura?", "Deixa os perigos mais visiveis. As torretas continuam disparando e o Colosso continua atacando. O sol e um conforto para os olhos,nao uma promessa de que todos vao voltar.")
		};

		internal static LoreProfile Get(string uid)
		{
			return Array.Find(All, (LoreProfile p) => p.Uid == uid);
		}

		internal static bool Apply(Graph graph, string uid)
		{
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			LoreProfile loreProfile = Get(uid);
			if (loreProfile == null || graph.isRunning)
			{
				return false;
			}
			Node primeNode = graph.primeNode;
			StatementNodeExt val = (StatementNodeExt)(object)((primeNode is StatementNodeExt) ? primeNode : null);
			Node? obj = graph.allNodes.Find((Node n) => n is MultipleChoiceNodeExt);
			MultipleChoiceNodeExt val2 = (MultipleChoiceNodeExt)(object)((obj is MultipleChoiceNodeExt) ? obj : null);
			if (val == null || val2 == null || ((Node)val).outConnections.Count != 1 || (object)((Node)val).outConnections[0].targetNode != val2 || val2.availableChoices.Count < 3 || val2.availableChoices.Count != ((Node)val2).outConnections.Count)
			{
				return false;
			}
			Node targetNode = ((Node)val2).outConnections[0].targetNode;
			StatementNodeExt val3 = (StatementNodeExt)(object)((targetNode is StatementNodeExt) ? targetNode : null);
			Node targetNode2 = ((Node)val2).outConnections[1].targetNode;
			StatementNodeExt val4 = (StatementNodeExt)(object)((targetNode2 is StatementNodeExt) ? targetNode2 : null);
			if (val3 == null || val4 == null)
			{
				return false;
			}
			if (val.statement != null && val.statement.text == loreProfile.Greeting && val3.statement != null && val3.statement.text == loreProfile.Answer && val4.statement != null && val4.statement.text == loreProfile.Story)
			{
				return false;
			}
			Statement statement = new Statement(loreProfile.Greeting);
			Statement statement2 = new Statement(loreProfile.Answer);
			Statement statement3 = new Statement(loreProfile.Story);
			Statement statement4 = new Statement(loreProfile.Topic);
			Statement statement5 = new Statement(loreProfile.Personal);
			val.statement = statement;
			val3.statement = statement2;
			val4.statement = statement3;
			val2.availableChoices[0].statement = statement4;
			val2.availableChoices[1].statement = statement5;
			return true;
		}
	}
}

BepInEx/plugins/Codex_Pantano_Vagalumes/CodexPantanoVagalumes.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexPantanoVagalumes
{
	internal static class FireflyDesign
	{
		internal struct Sample
		{
			internal float X;

			internal float Y;

			internal float Z;

			internal float Brightness;

			internal float Size;
		}

		internal const int PerGroup = 16;

		internal const int LightBudget = 4;

		internal const float ViewRange = 230f;

		internal const float LightViewRange = 85f;

		internal const float LightRange = 34f;

		internal const float LightIntensity = 2.2f;

		internal const float FlyRadius = 8.5f;

		internal const float MinHeight = 0.85f;

		internal const float MaxHeight = 3.45f;

		internal const float FadeSeconds = 4f;

		internal const float RoomX = 1783f;

		internal const float RoomZ = 1796.7f;

		internal const float CenterX = -1500f;

		internal const float CenterZ = -130f;

		internal static readonly float[,] Locations = new float[10, 2]
		{
			{ -1528f, -147f },
			{ -1477f, -135f },
			{ -1512f, -177f },
			{ -1453f, -95f },
			{ -1530f, -117f },
			{ -1484f, -70f },
			{ -1424f, -164f },
			{ -1518f, -202f },
			{ -1492f, -47f },
			{ -1560f, -110f }
		};

		internal static Sample Flight(int group, int index, double time)
		{
			double num = (double)group * 2.399963 + (double)index * 1.618034;
			double num2 = 2.5 + (double)(index % 7) * 0.78;
			double num3 = 0.18 + (double)(index % 5) * 0.025;
			return new Sample
			{
				X = (float)(Math.Sin(time * num3 + num) * num2 + Math.Sin(time * 0.41 + num * 2.0) * 0.8),
				Z = (float)(Math.Cos(time * num3 + num) * num2 + Math.Sin(time * 0.33 + num) * 0.7),
				Y = (float)(2.15 + Math.Sin(time * 0.47 + num) * 0.95 + Math.Sin(time * 0.19 + num * 3.0) * 0.35),
				Brightness = (float)(0.18 + 0.82 * Math.Pow(0.5 + 0.5 * Math.Sin(time * (1.02 + (double)(index % 3) * 0.18) + num), 2.0)),
				Size = 0.065f + (float)(index % 4) * 0.012f
			};
		}

		internal static float Fade(float current, bool night, float seconds)
		{
			if (float.IsNaN(current) || float.IsInfinity(current))
			{
				current = 0f;
			}
			if (float.IsNaN(seconds) || float.IsInfinity(seconds) || seconds < 0f)
			{
				seconds = 0f;
			}
			current = Math.Max(0f, Math.Min(1f, current));
			if (!night)
			{
				return Math.Max(0f, current - seconds / 4f);
			}
			return Math.Min(1f, current + seconds / 4f);
		}

		internal static bool Visible(string scene, bool local, float x, float y, float z)
		{
			double num = x - 1783f - -1500f;
			double num2 = z - 1796.7f - -130f;
			if (scene == "CierzoTutorial" && local && y > 220f)
			{
				return num * num + num2 * num2 <= 52900.0;
			}
			return false;
		}

		internal static float SpriteAlpha(float x, float y, bool halo)
		{
			float num = x * x + y * y;
			if (num >= 1f)
			{
				return 0f;
			}
			if (!halo)
			{
				return (float)Math.Exp((0f - num) * 12f) * Math.Min(1f, (1f - num) * 5f);
			}
			return (float)Math.Pow(1f - num, 3.0);
		}
	}
	internal sealed class FireflyVisual : MonoBehaviour
	{
		private ParticleSystem core;

		private ParticleSystem halo;

		private Particle[] cores;

		private Particle[] halos;

		private Material coreMaterial;

		private Material haloMaterial;

		private Texture2D coreSprite;

		private Texture2D haloSprite;

		private bool visible;

		internal void Build()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0086: 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)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00c4: 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)
			Shader val = Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("Particles/Alpha Blended") ?? Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Additive");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Shader nativo de particulas indisponivel;vagalumes omitidos,cenario preservado.");
			}
			coreSprite = Sprite(glow: false);
			haloSprite = Sprite(glow: true);
			coreMaterial = new Material(val)
			{
				name = "Vagalumes_Nucleo_Verde",
				mainTexture = (Texture)(object)coreSprite
			};
			haloMaterial = new Material(val)
			{
				name = "Vagalumes_Halo_Verde",
				mainTexture = (Texture)(object)haloSprite
			};
			if (coreMaterial.HasProperty("_TintColor"))
			{
				coreMaterial.SetColor("_TintColor", Color.white);
			}
			if (haloMaterial.HasProperty("_TintColor"))
			{
				haloMaterial.SetColor("_TintColor", Color.white);
			}
			int num = FireflyDesign.Locations.GetLength(0) * 16;
			cores = (Particle[])(object)new Particle[num];
			halos = (Particle[])(object)new Particle[num];
			core = System("Vagalumes_Nucleos", coreMaterial, num);
			halo = System("Vagalumes_Halos", haloMaterial, num);
		}

		private static Texture2D Sprite(bool glow)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = (glow ? "Vagalume_Halo_64" : "Vagalume_Nucleo_64"),
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					array[i * 64 + j] = new Color(1f, 1f, 1f, FireflyDesign.SpriteAlpha(((float)j + 0.5f) * 2f / 64f - 1f, ((float)i + 0.5f) * 2f / 64f - 1f, glow));
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		private ParticleSystem System(string name, Material material, int count)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0028: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = obj.main;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).simulationSpeed = 0f;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).maxParticles = count;
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(1000f);
			((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)3;
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).enabled = false;
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).enabled = false;
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = material;
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			component.sortMode = (ParticleSystemSortMode)1;
			return obj;
		}

		internal void Show(bool show)
		{
			if (visible != show)
			{
				visible = show;
				if (show)
				{
					core.Play();
					halo.Play();
				}
				else
				{
					core.Stop(true, (ParticleSystemStopBehavior)0);
					halo.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
		}

		internal void Draw(Vector3[] anchors, double time, float level)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			if (!visible)
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < anchors.Length; i++)
			{
				int num2 = 0;
				while (num2 < 16)
				{
					FireflyDesign.Sample sample = FireflyDesign.Flight(i, num2, time);
					Vector3 position = anchors[i] + new Vector3(sample.X, sample.Y, sample.Z);
					((Particle)(ref cores[num])).position = position;
					((Particle)(ref cores[num])).startSize = sample.Size;
					((Particle)(ref cores[num])).startColor = Color32.op_Implicit(new Color(0.68f, 1f, 0.28f, level * (0.3f + 0.7f * sample.Brightness)));
					((Particle)(ref cores[num])).startLifetime = 1000f;
					((Particle)(ref cores[num])).remainingLifetime = 1000f;
					((Particle)(ref halos[num])).position = position;
					((Particle)(ref halos[num])).startSize = sample.Size * (5f + sample.Brightness * 2f);
					((Particle)(ref halos[num])).startColor = Color32.op_Implicit(new Color(0.22f, 1f, 0.42f, level * sample.Brightness * 0.3f));
					((Particle)(ref halos[num])).startLifetime = 1000f;
					((Particle)(ref halos[num])).remainingLifetime = 1000f;
					num2++;
					num++;
				}
			}
			core.SetParticles(cores, num);
			halo.SetParticles(halos, num);
		}

		private void OnDestroy()
		{
			if ((Object)(object)coreMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)coreMaterial);
			}
			if ((Object)(object)haloMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)haloMaterial);
			}
			if ((Object)(object)coreSprite != (Object)null)
			{
				Object.Destroy((Object)(object)coreSprite);
			}
			if ((Object)(object)haloSprite != (Object)null)
			{
				Object.Destroy((Object)(object)haloSprite);
			}
		}
	}
	[BepInPlugin("codex.outward.pantano.vagalumes", "Codex - Vagalumes Noturnos do Pantano", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private GameObject root;

		private FireflyVisual visual;

		private Vector3[] anchors;

		private Collider[] supports;

		private Light[] lights;

		private float[] distances;

		private List<Character> players = new List<Character>();

		private float nextScan;

		private float nextBuild;

		private float nextDraw;

		private float lastScan;

		private float level;

		private float nextWarning;

		private double clock;

		private bool viewer;

		private bool? lastNight;

		private void Awake()
		{
			SceneManager.sceneLoaded += Loaded;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[Vagalumes]1.0.0;10grupos/160vagalumes verdes;noiteTOD_Sky.IsNight;max4luzes34m semsombras;sem fisica/nav/monstros alterados.");
		}

		private void Loaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
				nextScan = (nextBuild = 0f);
				lastNight = null;
				level = 0f;
			}
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "CierzoTutorial")
			{
				if ((Object)(object)root != (Object)null)
				{
					Cleanup();
				}
				return;
			}
			float seconds;
			TOD_Sky instance;
			int num;
			int num2;
			if (unscaledTime >= nextScan)
			{
				seconds = Mathf.Min(0.5f, Mathf.Max(0f, unscaledTime - lastScan));
				lastScan = unscaledTime;
				nextScan = unscaledTime + 0.25f;
				ScanPlayers();
				instance = TOD_Sky.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					num = (instance.Initialized ? 1 : 0);
					if (num != 0)
					{
						num2 = (instance.IsNight ? 1 : 0);
						goto IL_009f;
					}
				}
				else
				{
					num = 0;
				}
				num2 = 0;
				goto IL_009f;
			}
			goto IL_0265;
			IL_0265:
			if ((Object)(object)root == (Object)null || !viewer || level <= 0.001f)
			{
				return;
			}
			NetworkLevelLoader instance2 = NetworkLevelLoader.Instance;
			if (!((Object)(object)instance2 == (Object)null) && instance2.IsOverallLoadingDone && !instance2.IsGameplayPaused)
			{
				clock += Mathf.Min(Time.deltaTime, 0.1f);
				if (!(unscaledTime < nextDraw))
				{
					nextDraw = unscaledTime + 1f / 30f;
					visual.Draw(anchors, clock, level);
				}
			}
			return;
			IL_009f:
			bool flag = (byte)num2 != 0;
			level = FireflyDesign.Fade(level, flag, seconds);
			if (num != 0 && lastNight != flag)
			{
				lastNight = flag;
				((BaseUnityPlugin)this).Logger.LogMessage((object)("[Vagalumes]" + (flag ? "NOITE:acendendo" : "DIA:apagando") + ";fonteTOD_Sky.IsNight;hora=" + ((instance.Cycle == null) ? "?" : instance.Cycle.Hour.ToString("F2"))));
			}
			if (num == 0 && viewer && unscaledTime >= nextWarning)
			{
				nextWarning = unscaledTime + 30f;
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[Vagalumes]Aguardando ceu nativo;sem relogio confirmado fica apagado.");
			}
			if (viewer && flag && (Object)(object)root == (Object)null && unscaledTime >= nextBuild)
			{
				nextBuild = unscaledTime + 10f;
				try
				{
					Build();
				}
				catch (Exception ex)
				{
					Cleanup();
					((BaseUnityPlugin)this).Logger.LogError((object)("[Vagalumes]Falha isolada;cenario intacto:" + ex));
				}
			}
			if ((Object)(object)root != (Object)null)
			{
				bool flag2 = true;
				Collider[] array = supports;
				foreach (Collider val in array)
				{
					if ((Object)(object)val == (Object)null || !val.enabled || !((Component)val).gameObject.activeInHierarchy)
					{
						flag2 = false;
					}
				}
				if (!flag2)
				{
					Cleanup();
					nextBuild = unscaledTime + 2f;
					return;
				}
				visual.Show(viewer && level > 0.001f);
				SetLights();
			}
			goto IL_0265;
		}

		private void ScanPlayers()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			viewer = false;
			players.Clear();
			if ((Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			CharacterManager.Instance.FindCharactersInRange(new Vector3(283f, 255f, 1666.7f), 250f, ref players);
			foreach (Character player in players)
			{
				if ((Object)(object)player != (Object)null && FireflyDesign.Visible("CierzoTutorial", player.IsLocalPlayer, ((Component)player).transform.position.x, ((Component)player).transform.position.y, ((Component)player).transform.position.z))
				{
					viewer = true;
				}
			}
		}

		private static bool Floor(float x, float z, out Vector3 at, out Collider support)
		{
			//IL_0001: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			at = default(Vector3);
			support = null;
			GameObject val = GameObject.Find("Campo_Oeste_Setor_" + (int)Math.Floor((0f - x - 250f) / 125f) + "_" + (int)Math.Floor((z + 250f) / 125f));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			support = val.GetComponent<Collider>();
			RaycastHit val2 = default(RaycastHit);
			if ((Object)(object)support == (Object)null || !support.enabled || !((Component)support).gameObject.activeInHierarchy || !support.Raycast(new Ray(new Vector3(1783f + x, 280f, 1796.7f + z), Vector3.down), ref val2, 35f) || ((RaycastHit)(ref val2)).point.y < 220f)
			{
				return false;
			}
			at = ((RaycastHit)(ref val2)).point;
			return true;
		}

		private void Build()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_013c: 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)
			int length = FireflyDesign.Locations.GetLength(0);
			Vector3[] array = (Vector3[])(object)new Vector3[length];
			Collider[] array2 = (Collider[])(object)new Collider[length];
			for (int i = 0; i < length; i++)
			{
				if (!Floor(FireflyDesign.Locations[i, 0], FireflyDesign.Locations[i, 1], out array[i], out array2[i]))
				{
					((BaseUnityPlugin)this).Logger.LogMessage((object)("[Vagalumes]Aguardando piso real;grupo=" + (i + 1)));
					return;
				}
			}
			anchors = array;
			supports = array2;
			root = new GameObject("Codex_Pantano_Vagalumes_Noturnos");
			SceneManager.MoveGameObjectToScene(root, ((Component)array2[0]).gameObject.scene);
			visual = root.AddComponent<FireflyVisual>();
			visual.Build();
			lights = (Light[])(object)new Light[length];
			distances = new float[length];
			for (int j = 0; j < length; j++)
			{
				GameObject val = new GameObject("Vagalumes_Luz_Grupo_" + (j + 1));
				val.transform.SetParent(root.transform, false);
				val.transform.position = anchors[j] + Vector3.up * 2.25f;
				Light val2 = val.AddComponent<Light>();
				val2.type = (LightType)2;
				val2.color = new Color(0.34f, 1f, 0.48f);
				val2.range = 34f;
				val2.intensity = 0f;
				((Behaviour)val2).enabled = false;
				val2.shadows = (LightShadows)0;
				val2.renderMode = (LightRenderMode)1;
				lights[j] = val2;
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[Vagalumes]PRONTOS:10grupos/160pontos+halos64px;piso real;max4luzes locais34m;semcolisores;testevisualpendente.");
		}

		private void SetLights()
		{
			//IL_003a: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < lights.Length; i++)
			{
				float num = float.PositiveInfinity;
				foreach (Character player in players)
				{
					if ((Object)(object)player != (Object)null && player.IsLocalPlayer && ((Component)player).transform.position.y > 220f)
					{
						float num2 = num;
						Vector3 val = ((Component)player).transform.position - ((Component)lights[i]).transform.position;
						num = Mathf.Min(num2, ((Vector3)(ref val)).sqrMagnitude);
					}
				}
				distances[i] = num;
				((Behaviour)lights[i]).enabled = false;
			}
			if (!viewer || level <= 0.001f)
			{
				return;
			}
			for (int j = 0; j < 4; j++)
			{
				int num3 = -1;
				float num4 = 7225f;
				for (int k = 0; k < distances.Length; k++)
				{
					if (distances[k] < num4)
					{
						num4 = distances[k];
						num3 = k;
					}
				}
				if (num3 >= 0)
				{
					distances[num3] = float.PositiveInfinity;
					Light obj = lights[num3];
					((Behaviour)obj).enabled = true;
					obj.intensity = 2.2f * level * (0.91f + 0.09f * Mathf.Sin((float)clock * 0.8f + (float)num3));
					continue;
				}
				break;
			}
		}

		private void Cleanup()
		{
			if (lights != null)
			{
				Light[] array = lights;
				foreach (Light val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
			if ((Object)(object)root != (Object)null)
			{
				root.SetActive(false);
				Object.Destroy((Object)(object)root);
			}
			root = null;
			visual = null;
			anchors = null;
			supports = null;
			lights = null;
			distances = null;
			clock = 0.0;
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= Loaded;
			Cleanup();
		}
	}
}

BepInEx/plugins/Codex_Sala_Preto_Teste/CodexSalaPretoTeste.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using Microsoft.CodeAnalysis;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using SideLoader;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexSalaPretoTeste
{
	internal static class ArenaDialogue
	{
		private const string SpeakerName = "Ardan, Invocador da Arena";

		internal static bool Attach(Character character, TestSummoner summoner)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || (Object)(object)summoner == (Object)null)
			{
				return false;
			}
			ArenaDialogueHost arenaDialogueHost = ((Component)character).GetComponent<ArenaDialogueHost>();
			if ((Object)(object)arenaDialogueHost != (Object)null && arenaDialogueHost.Ready)
			{
				return true;
			}
			if ((Object)(object)arenaDialogueHost == (Object)null)
			{
				arenaDialogueHost = ((Component)character).gameObject.AddComponent<ArenaDialogueHost>();
			}
			GameObject val = arenaDialogueHost.Template;
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = Resources.Load<GameObject>("editor/templates/TrainerTemplate");
				if ((Object)(object)val2 == (Object)null)
				{
					Debug.LogError((object)"[SalaPreta] O molde nativo TrainerTemplate nao foi encontrado.");
					return false;
				}
				val = Object.Instantiate<GameObject>(val2);
				((Object)val).name = "Ardan_Arena_Dialogue";
				val.transform.SetParent(((Component)character).transform, false);
				val.transform.localPosition = Vector3.zero;
				val.transform.localRotation = Quaternion.identity;
				arenaDialogueHost.Template = val;
			}
			DialogueTreeController componentInChildren = val.GetComponentInChildren<DialogueTreeController>(true);
			DialogueActor componentInChildren2 = val.GetComponentInChildren<DialogueActor>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren2 == (Object)null)
			{
				return false;
			}
			Graph graph = ((GraphOwner)componentInChildren).graph;
			if ((Object)(object)graph == (Object)null)
			{
				return false;
			}
			SetupActor(graph, componentInChildren2);
			BuildGraph(graph);
			val.SetActive(true);
			((Component)character).gameObject.SetActive(true);
			arenaDialogueHost.Ready = true;
			return true;
		}

		private static void SetupActor(Graph graph, DialogueActor actor)
		{
			actor.SetName("Ardan, Invocador da Arena");
			DialogueTree val = (DialogueTree)(object)((graph is DialogueTree) ? graph : null);
			List<ActorParameter> list = (((Object)(object)val == (Object)null) ? null : (At.GetField<DialogueTree>(val, "_actorParameters") as List<ActorParameter>));
			if (list != null && list.Count > 0)
			{
				list[0].actor = (IDialogueActor)(object)actor;
				list[0].name = "Ardan, Invocador da Arena";
			}
		}

		private static void BuildGraph(Graph graph)
		{
			graph.allNodes.Clear();
			StatementNodeExt val = MakeStatement(graph, "O posto de testes esta pronto. Qual comando deseja executar?");
			MultipleChoiceNodeExt val2 = MakeChoices(graph, "Invocar o Desafiante Hostil salvo.", "Remover o especime atual.", "Nada por enquanto.");
			StatementNodeExt val3 = MakeStatement(graph, "Espaco liberado. O especime sera materializado adiante; prepare-se.");
			ArenaDialogueActionNode arenaDialogueActionNode = graph.AddNode<ArenaDialogueActionNode>();
			arenaDialogueActionNode.Command = ArenaDialogueCommand.Summon;
			StatementNodeExt val4 = MakeStatement(graph, "Teste encerrado. O especime atual sera removido.");
			ArenaDialogueActionNode arenaDialogueActionNode2 = graph.AddNode<ArenaDialogueActionNode>();
			arenaDialogueActionNode2.Command = ArenaDialogueCommand.Dismiss;
			StatementNodeExt val5 = MakeStatement(graph, "Volte quando trouxermos outro monstro para o arquivo.");
			graph.primeNode = (Node)(object)val;
			graph.ConnectNodes((Node)(object)val, (Node)(object)val2, -1, -1);
			graph.ConnectNodes((Node)(object)val2, (Node)(object)val3, 0, -1);
			graph.ConnectNodes((Node)(object)val3, (Node)(object)arenaDialogueActionNode, -1, -1);
			graph.ConnectNodes((Node)(object)val2, (Node)(object)val4, 1, -1);
			graph.ConnectNodes((Node)(object)val4, (Node)(object)arenaDialogueActionNode2, -1, -1);
			graph.ConnectNodes((Node)(object)val2, (Node)(object)val5, 2, -1);
		}

		private static StatementNodeExt MakeStatement(Graph graph, string text)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			StatementNodeExt obj = graph.AddNode<StatementNodeExt>();
			obj.statement = new Statement(text);
			obj.SetActorName("Ardan, Invocador da Arena");
			return obj;
		}

		private static MultipleChoiceNodeExt MakeChoices(Graph graph, params string[] labels)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			MultipleChoiceNodeExt val = graph.AddNode<MultipleChoiceNodeExt>();
			foreach (string text in labels)
			{
				val.availableChoices.Add(new Choice(new Statement(text)));
			}
			return val;
		}
	}
	internal enum ArenaDialogueCommand
	{
		Summon,
		Dismiss
	}
	internal sealed class ArenaDialogueActionNode : ActionNode
	{
		internal ArenaDialogueCommand Command;

		protected override Status OnExecute(Component agent, IBlackboard blackboard)
		{
			TestSummoner testSummoner = (((Object)(object)agent == (Object)null) ? null : agent.GetComponentInParent<TestSummoner>());
			if ((Object)(object)testSummoner == (Object)null)
			{
				testSummoner = Object.FindObjectOfType<TestSummoner>();
			}
			if ((Object)(object)testSummoner == (Object)null)
			{
				Debug.LogError((object)"[SalaPreta] O dialogo de Ardan nao encontrou o invocador.");
				return (Status)0;
			}
			if (Command == ArenaDialogueCommand.Summon)
			{
				testSummoner.RequestSummon();
			}
			else
			{
				testSummoner.DismissEnemy();
			}
			return (Status)1;
		}
	}
	internal sealed class ArenaDialogueHost : MonoBehaviour
	{
		internal GameObject Template;

		internal bool Ready;
	}
	[BepInPlugin("codex.outward.sala.preto.teste", "Codex - Complexo Negro de Teste", "1.52.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private VillageModelList _centralModels;

		private Dictionary<string, Mesh> _centralHouseMeshes;

		private Dictionary<string, Material> _centralHouseMaterials;

		private Texture2D _compactStoneTexture;

		private Texture2D _compactTimberTexture;

		internal static readonly Vector2[] FendaCrystalLots = (Vector2[])(object)new Vector2[11]
		{
			new Vector2(-29f, -21f),
			new Vector2(30f, -17f),
			new Vector2(-34f, 4f),
			new Vector2(32f, 7f),
			new Vector2(-29f, 25f),
			new Vector2(30f, 30f),
			new Vector2(9f, 39f),
			new Vector2(-12f, 38f),
			new Vector2(-40f, 40f),
			new Vector2(-8f, -18f),
			new Vector2(10f, -22f)
		};

		private static readonly Vector4[] FendaPaths = (Vector4[])(object)new Vector4[8]
		{
			new Vector4(0f, -31f, 0f, 5f),
			new Vector4(0f, 5f, -20f, -14f),
			new Vector4(0f, 10f, 21f, -12f),
			new Vector4(-2f, 16f, -22f, 12f),
			new Vector4(3f, 18f, 21f, 17f),
			new Vector4(0f, 18f, 0f, 34f),
			new Vector4(-9f, 16f, -34f, 37f),
			new Vector4(9f, 18f, 38f, 43f)
		};

		internal static readonly Vector4[] FendaTreeLots = (Vector4[])(object)new Vector4[5]
		{
			new Vector4(-35f, -24f, 5.7f, 23f),
			new Vector4(35f, -25f, 5f, 152f),
			new Vector4(-41f, 16f, 6.2f, 247f),
			new Vector4(39f, 24f, 5.5f, 83f),
			new Vector4(-15f, 43f, 4.8f, 194f)
		};

		private const int CanyonChunkSegments = 8;

		private const int CanyonBands = 10;

		private const int CanyonGateStart = 198;

		private const int CanyonGateEnd = 201;

		private readonly Dictionary<string, Mesh> _cottageMeshes = new Dictionary<string, Mesh>();

		internal static readonly Vector3 MechanicalArenaLocal = new Vector3(-1800f, 0f, 78f);

		internal const float MechanicalArenaRadius = 42f;

		internal const float MechanicalArenaWallHeight = 5.8f;

		internal const float MechanicalArenaGateAngle = 14f;

		internal static readonly Vector3 NewBiomePortalLocal = new Vector3(-1500f, 0f, -130f);

		internal static readonly Vector3 NewBiomeArrivalLocal = NewBiomePortalLocal + Vector3.back * 5f;

		internal static readonly Vector3 NewBiomeMarkerLocal = NewBiomePortalLocal + new Vector3(7f, 0f, 11f);

		public const string Guid = "codex.outward.sala.preto.teste";

		public const string Name = "Codex - Complexo Negro de Teste";

		public const string Version = "1.52.5";

		internal const string TargetScene = "CierzoTutorial";

		internal static readonly Vector3 EntrancePosition = new Vector3(1783f, 5.1f, 1796.7f);

		internal static readonly Vector3 ReturnPosition = new Vector3(1783f, 5.7f, 1792.8f);

		internal static readonly Vector3 RoomCenter = new Vector3(1783f, 255f, 1796.7f);

		internal static readonly Vector3 RoomSpawn = RoomCenter + new Vector3(0f, 1.25f, -32f);

		internal static readonly Vector3 IceDistrictCenter = RoomCenter + new Vector3(122f, 0f, 62f);

		private string _builtScene = string.Empty;

		private GameObject _roomRoot;

		private NavMeshDataInstance _iceNavMeshInstance;

		private NavMeshData _iceNavMeshData;

		private RoomAssetScope _assets;

		private readonly Dictionary<string, Texture2D> _loadedTextures = new Dictionary<string, Texture2D>();

		private MeshFilter[] _nativeMeshes;

		private SceneryLayout _scatterLayout;

		private readonly List<SceneryEntry> _placedScenery = new List<SceneryEntry>();

		private const int MeadowSegments = 256;

		private const int MeadowRings = 64;

		internal static readonly Vector3 NewAreaLocal = new Vector3(-850f, 0f, -100f);

		internal static readonly Vector3 NewAreaArrivalLocal = NewAreaLocal + new Vector3(0f, 0f, -5f);

		internal static readonly Vector3 NewAreaStoneLocal = NewAreaLocal + new Vector3(5f, 0f, 4f);

		internal static readonly float[] NewAreaEntranceOffsets = new float[4] { 7f, -7f, 10f, -10f };

		internal static readonly Vector3 MechanicalAreaLocal = new Vector3(-1800f, 0f, 30f);

		internal static readonly Vector3 MechanicalArrivalLocal = MechanicalAreaLocal + Vector3.back * 5f;

		internal static readonly Vector3 MechanicalLandmarkLocal = MechanicalAreaLocal + new Vector3(0f, 0f, 81f);

		internal static readonly Vector3 FendaLocal = NewAreaLocal + new Vector3(0f, 0f, 24f);

		internal static readonly FendaHouse[] FendaHouses = new FendaHouse[5]
		{
			new FendaHouse("timber", -20f, -14f, 25f, 1.35f, ruined: false),
			new FendaHouse("stone", 21f, -12f, -35f, 1.45f, ruined: false),
			new FendaHouse("stone", -22f, 12f, -15f, 1.25f, ruined: true),
			new FendaHouse("timber", 21f, 17f, -155f, 1.4f, ruined: true),
			new FendaHouse("timber", 0f, 34f, 180f, 1.45f, ruined: false)
		};

		private List<Collider> _fendaGround;

		private Collider[] _villageGround;

		private VillageLayout _villageLayout;

		private const int WestFieldColumns = 16;

		private const int WestFieldRows = 4;

		private const int WestFieldCells = 25;

		private const float WestFieldChunkSize = 125f;

		private const float WestFieldLength = 2000f;

		private const float WestFieldWidth = 500f;

		private Material BluePortalMaterial(bool wisp, Material nativeDefault)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_00f0: 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)
			Material val = (wisp ? _assets.PortalWisp : _assets.PortalGlow);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Shader val2 = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Additive") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("Particles/Alpha Blended");
			if ((Object)(object)val2 == (Object)null && (Object)(object)nativeDefault != (Object)null && nativeDefault.HasProperty("_MainTex") && (Object)(object)nativeDefault.shader != (Object)null && ((Object)nativeDefault.shader).name != "Hidden/InternalErrorShader")
			{
				val2 = nativeDefault.shader;
			}
			if ((Object)(object)val2 == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[PortalAzul] Shader de particulas indisponivel;sem quadrados de fallback.");
				return null;
			}
			Texture2D val3 = Own<Texture2D>(PortalTextureUpload.Create(wisp));
			Material val4 = Own<Material>(((Object)(object)nativeDefault != (Object)null && (Object)(object)val2 == (Object)(object)nativeDefault.shader) ? new Material(nativeDefault) : new Material(val2));
			((Object)val4).name = ((Object)val3).name;
			val4.mainTexture = (Texture)(object)val3;
			if (val4.HasProperty("_TintColor"))
			{
				val4.SetColor("_TintColor", Color.white);
			}
			if (wisp)
			{
				_assets.PortalWisp = val4;
			}
			else
			{
				_assets.PortalGlow = val4;
			}
			return val4;
		}

		private void CreateBluePortalParticles(string name, Vector3 position, bool rising)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_0115: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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_0265: 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_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Expected O, but got Unknown
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: 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_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: 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_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Expected O, but got Unknown
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				val = new GameObject(name);
				val.transform.SetParent(_roomRoot.transform, true);
				val.transform.position = position;
				if (rising)
				{
					val.transform.rotation = Quaternion.Euler(-90f, 0f, 0f);
				}
				ParticleSystem val2 = val.AddComponent<ParticleSystem>();
				val2.Stop(true, (ParticleSystemStopBehavior)0);
				ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
				Material val3 = BluePortalMaterial(!rising, ((Renderer)component).sharedMaterial);
				if ((Object)(object)val3 == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					return;
				}
				MainModule main = val2.main;
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(rising ? 1.4f : 2f, rising ? 2.6f : 3.1f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(rising ? 0.35f : 0.015f, rising ? 0.85f : 0.08f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(rising ? 0.055f : 0.17f, rising ? 0.13f : 0.38f);
				((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, (float)Math.PI * 2f);
				((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.18f, 0.48f, 1f, 0.65f), new Color(0.55f, 0.94f, 1f, 0.92f));
				((MainModule)(ref main)).maxParticles = (rising ? 64 : 96);
				((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)2;
				EmissionModule emission = val2.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit((float)(rising ? 18 : 25));
				ShapeModule shape = val2.shape;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)(rising ? 4 : 10);
				((ShapeModule)(ref shape)).radius = (rising ? 1.1f : 1.25f);
				if (rising)
				{
					((ShapeModule)(ref shape)).angle = 7f;
				}
				VelocityOverLifetimeModule velocityOverLifetime = val2.velocityOverLifetime;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
				if (!rising)
				{
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ = new MinMaxCurve(0.65f, 1.05f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = MinMaxCurve.op_Implicit(-0.1f);
				}
				NoiseModule noise = val2.noise;
				((NoiseModule)(ref noise)).enabled = true;
				((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(rising ? 0.06f : 0.1f);
				((NoiseModule)(ref noise)).frequency = 0.8f;
				((NoiseModule)(ref noise)).scrollSpeed = MinMaxCurve.op_Implicit(0.25f);
				((NoiseModule)(ref noise)).octaveCount = 1;
				((NoiseModule)(ref noise)).quality = (ParticleSystemNoiseQuality)0;
				ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
				Gradient val4 = new Gradient();
				val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
				{
					new GradientColorKey(new Color(0.12f, 0.35f, 1f), 0f),
					new GradientColorKey(new Color(0.5f, 0.94f, 1f), 0.45f),
					new GradientColorKey(new Color(0.2f, 0.48f, 0.9f), 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
				{
					new GradientAlphaKey(0f, 0f),
					new GradientAlphaKey(0.8f, 0.15f),
					new GradientAlphaKey(0.65f, 0.6f),
					new GradientAlphaKey(0f, 1f)
				});
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val4);
				SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[3]
				{
					new Keyframe(0f, 0.15f),
					new Keyframe(0.25f, 1f),
					new Keyframe(1f, 0.05f)
				}));
				((Renderer)component).sharedMaterial = val3;
				component.renderMode = (ParticleSystemRenderMode)0;
				((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)component).receiveShadows = false;
				component.maxParticleSize = 0.15f;
				val2.Play();
				((BaseUnityPlugin)this).Logger.LogMessage((object)("[PortalAzul] " + name + ":sprite128RGBA/alpha suave;" + (rising ? "faiscas ascendentes" : "filamentos em espiral") + ";max" + ((MainModule)(ref main)).maxParticles + ";sem novas luzes/colliders."));
			}
			catch (Exception ex)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
					Object.Destroy((Object)(object)val);
				}
				((BaseUnityPlugin)this).Logger.LogError((object)("[PortalAzul] Efeito isolado falhou: " + name + ";construcao da cidade continua. " + ex));
			}
		}

		private bool TryLoadCentralResidenceAssets()
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets", "VillageHouses");
				_centralModels = VillageData.ReadModels(Path.Combine(text, "models.json"));
				_centralHouseMeshes = new Dictionary<string, Mesh>();
				_centralHouseMaterials = new Dictionary<string, Material>();
				string[] array = new string[2] { "stone", "timber" };
				foreach (string name in array)
				{
					VillageModelPart[] parts = (Array.Find(_centralModels.models, (VillageModel value) => value.name == name) ?? throw new InvalidDataException("Casa central ausente: " + name)).parts;
					foreach (VillageModelPart villageModelPart in parts)
					{
						Mesh val = LoadCottageObj(Path.Combine(text, villageModelPart.mesh));
						val.RecalculateTangents();
						Material val2 = CreateMaterial(Color.white, Color.black);
						val2.DisableKeyword("_EMISSION");
						val2.mainTexture = (Texture)(object)LoadOrganicTexture(text, Path.GetFileNameWithoutExtension(villageModelPart.diffuse), normal: false);
						if ((Object)(object)val2.mainTexture == (Object)null)
						{
							throw new InvalidDataException("Textura central ausente: " + villageModelPart.diffuse);
						}
						if (val2.HasProperty("_Glossiness"))
						{
							val2.SetFloat("_Glossiness", 0.12f);
						}
						if (!string.IsNullOrEmpty(villageModelPart.normal) && val2.HasProperty("_BumpMap"))
						{
							val2.SetTexture("_BumpMap", (Texture)(object)LoadOrganicTexture(text, Path.GetFileNameWithoutExtension(villageModelPart.normal), normal: true));
							val2.SetFloat("_BumpScale", 0.45f);
							val2.EnableKeyword("_NORMALMAP");
						}
						_centralHouseMeshes.Add(villageModelPart.mesh, val);
						_centralHouseMaterials.Add(villageModelPart.mesh, val2);
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[CasasCentrais] Importacao falhou;ruinas anteriores preservadas: " + ex));
				return false;
			}
		}

		private void CreateCentralResidence(int index, Vector3 foundationTop)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00c6: 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_00ef: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			string name = ((index % 2 == 0) ? "stone" : "timber");
			float num = ((name == "stone") ? 1.4f : 1.55f);
			float num2 = ((!(name == "stone")) ? ((index == 1) ? 180 : 0) : ((index == 0) ? 90 : (-90)));
			VillageModel villageModel = Array.Find(_centralModels.models, (VillageModel value) => value.name == name);
			GameObject val = new GameObject("Residencia_Central_" + index + "_" + name);
			val.transform.SetParent(_roomRoot.transform, false);
			val.transform.position = foundationTop;
			val.transform.rotation = Quaternion.Euler(0f, num2, 0f);
			val.transform.localScale = Vector3.one * num;
			VillageModelPart[] parts = villageModel.parts;
			foreach (VillageModelPart villageModelPart in parts)
			{
				GameObject val2 = new GameObject("Residencia_Modelo_" + villageModelPart.mesh);
				val2.transform.SetParent(val.transform, false);
				val2.AddComponent<MeshFilter>().sharedMesh = _centralHouseMeshes[villageModelPart.mesh];
				((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = _centralHouseMaterials[villageModelPart.mesh];
				val2.AddComponent<MeshCollider>().sharedMesh = _centralHouseMeshes[villageModelPart.mesh];
				VillageShadowsOff(val2);
			}
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.center = new Vector3(0f, villageModel.height * 0.3f, 0f);
			obj.size = new Vector3(villageModel.width * 0.88f, villageModel.height * 0.6f, villageModel.depth * 0.88f);
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[CasasCentrais] PRONTO:" + index + ";" + name + ";pos=" + FormatVector(foundationTop) + ";escala=" + num + ";yaw=" + num2 + ";texturasCC0<=1K;solid/nativeNav."));
		}

		private IEnumerator FinishCitySurfacesAfterBuild(GameObject root)
		{
			yield return null;
			if ((Object)(object)root == (Object)null || (Object)(object)root != (Object)(object)_roomRoot)
			{
				yield break;
			}
			CityPavingTextures sources = null;
			try
			{
				FinishExistingFoundations(root);
				sources = new CityPavingTextures(SnapshotFendaTexture("Fenda/rocky_terrain_diff_1k.jpg"), SnapshotFendaTexture("Snow/snow_02_diff_1k.jpg"), SnapshotFendaTexture("Fenda/rocky_terrain_nor_gl_1k.jpg"), SnapshotFendaTexture("Snow/snow_02_nor_gl_1k.jpg"));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[AcabamentoCidade] Textura indisponivel;piso original preservado: " + ex));
			}
			if (sources == null)
			{
				yield break;
			}
			Task<FendaSurfaceBake> task = Task.Run(() => sources.Bake());
			while (!task.IsCompleted)
			{
				yield return null;
				if ((Object)(object)root == (Object)null || (Object)(object)root != (Object)(object)_roomRoot)
				{
					yield break;
				}
			}
			if ((Object)(object)root == (Object)null || (Object)(object)root != (Object)(object)_roomRoot)
			{
				yield break;
			}
			try
			{
				FinishCentralPaving(root, task.GetAwaiter().GetResult());
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[AcabamentoCidade] Pavimento original preservado: " + ex2));
			}
		}

		private void FinishCentralPaving(GameObject root, FendaSurfaceBake bake)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = root.transform.Find("Laje_Cidade_Continua");
			MeshFilter val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<MeshFilter>());
			MeshRenderer val3 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<MeshRenderer>());
			if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null || (Object)(object)((Renderer)val3).sharedMaterial == (Object)null)
			{
				throw new InvalidOperationException("Piso visual central ausente");
			}
			Mesh sharedMesh = val2.sharedMesh;
			Material sharedMaterial = ((Renderer)val3).sharedMaterial;
			Texture2D val4 = Own<Texture2D>(new Texture2D(1024, 1024, (TextureFormat)3, true));
			Color[] array = (Color[])(object)new Color[1048576];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Color((float)(int)bake.Albedo[i * 3] / 255f, (float)(int)bake.Albedo[i * 3 + 1] / 255f, (float)(int)bake.Albedo[i * 3 + 2] / 255f, 1f);
			}
			((Object)val4).name = "Cidade_Pedra_Neve_Acabamento_1K";
			((Texture)val4).wrapMode = (TextureWrapMode)1;
			((Texture)val4).filterMode = (FilterMode)2;
			((Texture)val4).anisoLevel = 4;
			val4.SetPixels(array);
			val4.Apply(true, true);
			Material val5 = Own<Material>(new Material(sharedMaterial));
			((Object)val5).name = ((Object)val4).name;
			if (!val5.HasProperty("_MainTex"))
			{
				throw new InvalidOperationException("Piso sem MainTex");
			}
			val5.mainTexture = (Texture)(object)val4;
			val5.mainTextureScale = Vector2.one;
			val5.mainTextureOffset = Vector2.zero;
			val5.color = Color.white;
			val5.DisableKeyword("_DETAIL_MULX2");
			val5.DisableKeyword("_EMISSION");
			if (val5.HasProperty("_DetailAlbedoMap"))
			{
				val5.SetTexture("_DetailAlbedoMap", (Texture)null);
			}
			if (val5.HasProperty("_MetallicGlossMap"))
			{
				val5.SetTexture("_MetallicGlossMap", (Texture)null);
			}
			val5.DisableKeyword("_METALLICGLOSSMAP");
			if (val5.HasProperty("_Glossiness"))
			{
				val5.SetFloat("_Glossiness", 0.12f);
			}
			if (val5.HasProperty("_Metallic"))
			{
				val5.SetFloat("_Metallic", 0f);
			}
			if (val5.HasProperty("_BumpMap"))
			{
				Texture2D val6 = Own<Texture2D>(new Texture2D(512, 512, (TextureFormat)4, true, true));
				Color[] array2 = (Color[])(object)new Color[262144];
				for (int j = 0; j < array2.Length; j++)
				{
					array2[j] = new Color(1f, (float)(int)bake.Normals[j * 2 + 1] / 255f, 1f, (float)(int)bake.Normals[j * 2] / 255f);
				}
				((Texture)val6).wrapMode = (TextureWrapMode)1;
				((Texture)val6).filterMode = (FilterMode)2;
				((Texture)val6).anisoLevel = 4;
				val6.SetPixels(array2);
				val6.Apply(true, true);
				val5.SetTexture("_BumpMap", (Texture)(object)val6);
				val5.SetTextureScale("_BumpMap", Vector2.one);
				val5.SetTextureOffset("_BumpMap", Vector2.zero);
				val5.SetFloat("_BumpScale", 0.35f);
				val5.EnableKeyword("_NORMALMAP");
			}
			Mesh val7 = Own<Mesh>(Object.Instantiate<Mesh>(sharedMesh));
			Vector3[] vertices = val7.vertices;
			Vector2[] array3 = (Vector2[])(object)new Vector2[vertices.Length];
			for (int k = 0; k < array3.Length; k++)
			{
				array3[k] = new Vector2((0.5f + (vertices[k].x + 60f) / 120f * 1023f) / 1024f, (0.5f + (vertices[k].z + 60f) / 120f * 1023f) / 1024f);
			}
			val7.uv = array3;
			val7.RecalculateTangents();
			try
			{
				val2.sharedMesh = val7;
				((Renderer)val3).sharedMaterial = val5;
			}
			catch
			{
				val2.sharedMesh = sharedMesh;
				((Renderer)val3).sharedMaterial = sharedMaterial;
				throw;
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[AcabamentoCidade] PRONTO:pedra gasta/caminhos/neve junto a mureta1K;mesmo pavimento,sem collider/altura nova.");
		}

		private void FinishExistingFoundations(GameObject root)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadTextureAsset("Fenda/rocky_terrain_diff_1k.jpg", packAsNormal: false, invertRoughness: false);
			Texture2D val2 = LoadTextureAsset("Fenda/rocky_terrain_nor_gl_1k.jpg", packAsNormal: true, invertRoughness: false);
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Pedra de fundacao ausente");
			}
			Material val3 = CreateMaterial(new Color(0.62f, 0.66f, 0.68f), Color.black);
			val3.DisableKeyword("_EMISSION");
			val3.mainTexture = (Texture)(object)val;
			val3.mainTextureScale = Vector2.one;
			if (val3.HasProperty("_Glossiness"))
			{
				val3.SetFloat("_Glossiness", 0.12f);
			}
			if ((Object)(object)val2 != (Object)null && val3.HasProperty("_BumpMap"))
			{
				val3.SetTexture("_BumpMap", (Texture)(object)val2);
				val3.SetTextureScale("_BumpMap", Vector2.one);
				val3.SetFloat("_BumpScale", 0.38f);
				val3.EnableKeyword("_NORMALMAP");
			}
			int num = 0;
			MeshFilter[] componentsInChildren = root.GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val4 in componentsInChildren)
			{
				if (((Object)val4).name != "Aldeia_Fundacao" && ((Object)val4).name != "Santuario_Portal_Base" && ((Object)val4).name != "Ruina_Base")
				{
					continue;
				}
				MeshRenderer component = ((Component)val4).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null || (Object)(object)val4.sharedMesh == (Object)null)
				{
					continue;
				}
				Mesh sharedMesh = val4.sharedMesh;
				Material sharedMaterial = ((Renderer)component).sharedMaterial;
				Mesh val5 = Own<Mesh>(Object.Instantiate<Mesh>(sharedMesh));
				Vector3[] vertices = val5.vertices;
				Vector3[] normals = val5.normals;
				if (vertices.Length == normals.Length)
				{
					Vector2[] array = (Vector2[])(object)new Vector2[vertices.Length];
					for (int j = 0; j < array.Length; j++)
					{
						Vector3 val6 = ((Component)val4).transform.TransformPoint(vertices[j]) - RoomCenter;
						Vector3 val7 = ((Component)val4).transform.TransformDirection(normals[j]);
						array[j] = ((Mathf.Abs(val7.y) > 0.7f) ? (new Vector2(val6.x, val6.z) / 2.5f) : ((Mathf.Abs(val7.x) > Mathf.Abs(val7.z)) ? (new Vector2(val6.z, val6.y) / 2.5f) : (new Vector2(val6.x, val6.y) / 2.5f)));
					}
					val5.uv = array;
					val5.RecalculateTangents();
					try
					{
						val4.sharedMesh = val5;
						((Renderer)component).sharedMaterial = val3;
						num++;
					}
					catch
					{
						val4.sharedMesh = sharedMesh;
						((Renderer)component).sharedMaterial = sharedMaterial;
						throw;
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[AcabamentoCidade] Fundacoes:" + num + " acabamentos de pedra2.5m;volumes e apoio intactos."));
		}

		private void CreateUnifiedCityPaving(Material stone)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cf: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = Own<Mesh>(new Mesh
			{
				name = "Piso_Central_Continuo"
			});
			val.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-60f, -0.02f, -60f),
				new Vector3(-60f, -0.02f, 60f),
				new Vector3(60f, -0.02f, 60f),
				new Vector3(60f, -0.02f, -60f)
			};
			val.triangles = new int[6] { 0, 1, 2, 0, 2, 3 };
			val.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(-15f, -15f),
				new Vector2(-15f, 15f),
				new Vector2(15f, 15f),
				new Vector2(15f, -15f)
			};
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject("Laje_Cidade_Continua");
			val2.transform.SetParent(_roomRoot.transform, false);
			val2.transform.position = RoomCenter;
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = stone;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[SalaPreta] Piso visual:225 pecas substituidas por1 mesh/2 triangulos; colisao preservada.");
		}

		private void CreateCityWinterDetails(Material snow, Material stone, Material glow)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Expected O, but got Unknown
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: 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_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Expected O, but got Unknown
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: 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_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: 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_049c: 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)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] array = (Vector2[])(object)new Vector2[9]
			{
				new Vector2(-54f, -40f),
				new Vector2(54f, -40f),
				new Vector2(-54f, 38f),
				new Vector2(54f, 38f),
				new Vector2(-40f, 55f),
				new Vector2(0f, 55f),
				new Vector2(40f, 55f),
				new Vector2(-40f, -55f),
				new Vector2(40f, -55f)
			};
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			Vector3 val = default(Vector3);
			for (int i = 0; i < array.Length; i++)
			{
				int count = list.Count;
				list.Add(new Vector3(array[i].x, 0.11f, array[i].y));
				list2.Add(array[i] / 4f);
				for (int j = 1; j <= 3; j++)
				{
					for (int k = 0; k < 24; k++)
					{
						float num = (float)k * (float)Math.PI * 2f / 24f;
						float num2 = (float)j / 3f * (0.86f + Mathf.Sin(num * 3f + (float)i) * 0.09f + Mathf.Cos(num * 5f - (float)i) * 0.05f);
						((Vector3)(ref val))..ctor(array[i].x + Mathf.Cos(num) * num2 * 4f, 0.035f + 0.075f * (1f - (float)j / 3f) * (1f - (float)j / 3f), array[i].y + Mathf.Sin(num) * num2 * 3f);
						list.Add(val);
						list2.Add(new Vector2(val.x, val.z) / 4f);
					}
				}
				for (int l = 0; l < 24; l++)
				{
					int num3 = (l + 1) % 24;
					list3.Add(count);
					list3.Add(count + 1 + num3);
					list3.Add(count + 1 + l);
					for (int m = 0; m < 2; m++)
					{
						int num4 = count + 1 + m * 24 + l;
						int num5 = count + 1 + m * 24 + num3;
						int item = num4 + 24;
						int item2 = num5 + 24;
						list3.Add(num4);
						list3.Add(num5);
						list3.Add(item);
						list3.Add(num5);
						list3.Add(item2);
						list3.Add(item);
					}
				}
			}
			Mesh val2 = Own<Mesh>(new Mesh
			{
				name = "Neve_Margens_Centro"
			});
			val2.SetVertices(list);
			val2.SetUVs(0, list2);
			val2.SetTriangles(list3, 0);
			val2.RecalculateNormals();
			val2.RecalculateTangents();
			val2.RecalculateBounds();
			GameObject val3 = new GameObject("Neve_Margens_Centro");
			val3.transform.SetParent(_roomRoot.transform, false);
			val3.transform.position = RoomCenter;
			val3.AddComponent<MeshFilter>().sharedMesh = val2;
			Material val4 = Own<Material>(new Material(snow));
			val4.mainTextureScale = Vector2.one;
			if (val4.HasProperty("_BumpMap"))
			{
				val4.SetTextureScale("_BumpMap", Vector2.one);
			}
			if (val4.HasProperty("_MetallicGlossMap"))
			{
				val4.SetTextureScale("_MetallicGlossMap", Vector2.one);
			}
			MeshRenderer obj = val3.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = val4;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			Vector3[] array2 = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-39f, 0f, -31f),
				new Vector3(39f, 0f, -31f),
				new Vector3(-43f, 0f, 25f),
				new Vector3(43f, 0f, 25f)
			};
			for (int n = 0; n < array2.Length; n++)
			{
				Vector3 val5 = RoomCenter + array2[n] + new Vector3(-5.8f, 0.44f, -3.5f);
				CreateCylinder("Lanterna_Ruina_Base_" + n, val5 + Vector3.up * 0.08f, new Vector3(0.5f, 0.08f, 0.5f), stone, collider: false);
				CreateCylinder("Lanterna_Ruina_Haste_" + n, val5 + Vector3.up * 0.42f, new Vector3(0.08f, 0.34f, 0.08f), stone, collider: false);
				CreateSphere("Lanterna_Ruina_Lume_" + n, val5 + Vector3.up * 0.85f, new Vector3(0.22f, 0.32f, 0.22f), glow, collider: false);
				CreateCylinder("Lanterna_Ruina_Tampa_" + n, val5 + Vector3.up * 1.05f, new Vector3(0.32f, 0.04f, 0.32f), stone, collider: false);
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[SalaPreta]9 manchas de neve em1 mesh e4 lanternas sem luz adicional/colisao; arena e portais livres.");
		}

		private Texture2D CompactStoneTexture()
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_compactStoneTexture != (Object)null)
			{
				return _compactStoneTexture;
			}
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				int num = i / 32;
				for (int j = 0; j < 128; j++)
				{
					bool num2 = (j + num % 2 * 32) % 64 < 2 || i % 32 < 2;
					float num3 = Mathf.PerlinNoise((float)j * 0.047f + 4.7f, (float)i * 0.053f + 9.1f);
					float num4 = (float)((j * 37 + i * 73 + j * i * 3) & 0xF) / 15f;
					float num5 = (num2 ? 0.67f : (0.82f + (num3 - 0.5f) * 0.18f + (num4 - 0.5f) * 0.055f));
					array[i * 128 + j] = new Color(num5, num5, num5, 1f);
				}
			}
			_compactStoneTexture = MakeCompactTexture("Codex_Pedra_Compacta_128", array, 128);
			return _compactStoneTexture;
		}

		private Texture2D CompactTimberTexture()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_compactTimberTexture != (Object)null)
			{
				return _compactTimberTexture;
			}
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = Mathf.PerlinNoise((float)j * 0.032f + 13f, (float)i * 0.061f + 7f);
					float num2 = Mathf.Sin((float)i * 0.37f + num * 4f);
					float num3 = ((i % 32 < 2) ? 0.68f : (0.84f + num2 * 0.09f + (num - 0.5f) * 0.09f));
					array[i * 128 + j] = new Color(num3, num3, num3, 1f);
				}
			}
			_compactTimberTexture = MakeCompactTexture("Codex_Madeira_Compacta_128", array, 128);
			return _compactTimberTexture;
		}

		private Texture2D MakeCompactTexture(string name, Color[] pixels, int size)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			Texture2D obj = Own<Texture2D>(new Texture2D(size, size, (TextureFormat)3, true));
			((Object)obj).name = name;
			((Texture)obj).wrapMode = (TextureWrapMode)0;
			((Texture)obj).filterMode = (FilterMode)2;
			obj.SetPixels(pixels);
			obj.Apply(true, true);
			return obj;
		}

		private void CreateFendaFieldScenery(Material stone, Material wood, Material iron)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: 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_0346: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets", "OrganicWinter");
			Mesh[] array = (Mesh[])(object)new Mesh[3];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = LoadCottageObj(Path.Combine(path, "boulder_" + (i + 1) + ".obj"));
				array[i].RecalculateTangents();
			}
			Mesh val = LoadCottageObj(Path.Combine(path, "fallen_tree.obj"));
			val.RecalculateTangents();
			Material sharedMaterial = ((Renderer)((Component)_roomRoot.transform.Find("VilaFenda_Tronco_Caido_0")).GetComponent<MeshRenderer>()).sharedMaterial;
			Material val2 = Own<Material>(new Material(sharedMaterial));
			val2.color = new Color(0.7f, 0.64f, 0.53f);
			val2.DisableKeyword("_EMISSION");
			if (val2.HasProperty("_BumpMap"))
			{
				val2.SetFloat("_BumpScale", 0.45f);
				val2.EnableKeyword("_NORMALMAP");
			}
			Material[] array2 = (Material[])(object)new Material[3];
			Color[] array3 = (Color[])(object)new Color[3]
			{
				new Color(0.53f, 0.59f, 0.62f),
				new Color(0.68f, 0.57f, 0.43f),
				new Color(0.38f, 0.48f, 0.33f)
			};
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j] = Own<Material>(new Material(stone));
				array2[j].color = array3[j];
				((Object)array2[j]).name = "VilaFenda_Campo_Pedra_" + j;
			}
			MeshFilter val3 = FindNativeMesh("crate", "woodbox", "wood_box");
			MeshFilter val4 = FindNativeMesh("barrel", "cask");
			int num = 0;
			int num2 = 0;
			for (int k = 0; k < FendaFieldLayout.Sites.Length; k++)
			{
				FendaFieldSite fendaFieldSite = FendaFieldLayout.Sites[k];
				Physics.SyncTransforms();
				Vector3 foot = FendaPoint(fendaFieldSite.X, fendaFieldSite.Z);
				if (!FendaFieldSiteClear(foot))
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("[FendaCampo] OMITIDO grupo" + k + " por obstaculo existente."));
					continue;
				}
				int childCount = _roomRoot.transform.childCount;
				try
				{
					if (fendaFieldSite.Kind == 0)
					{
						for (int l = 0; l < 3; l++)
						{
							float num3 = fendaFieldSite.X + (float)(l - 1) * 1.6f;
							float num4 = fendaFieldSite.Z + ((l == 1) ? 1.3f : 0f);
							Vector3 val5 = FendaPoint(num3, num4);
							float num5 = val5.y;
							for (int m = -1; m <= 1; m++)
							{
								for (int n = -1; n <= 1; n++)
								{
									num5 = Mathf.Min(num5, FendaPoint(num3 + (float)m * 0.85f, num4 + (float)n * 0.85f).y);
								}
							}
							val5.y = num5 - 0.025f;
							int childCount2 = _roomRoot.transform.childCount;
							CreateSupplyProp((l == 2) ? val4 : val3, val5, (l == 0) ? 1.25f : 1f, fendaFieldSite.Yaw + (float)(l * 23), l == 2, wood, iron);
							((Object)_roomRoot.transform.GetChild(childCount2)).name = "VilaFenda_Campo_Suprimento_" + k + "_" + l;
						}
					}
					else
					{
						if (fendaFieldSite.Kind == 1)
						{
							FendaImportedProp("VilaFenda_Campo_Tronco_" + k, val, fendaFieldSite.X, fendaFieldSite.Z, 3.8f, fendaFieldSite.Yaw, val2, upright: false);
						}
						int num6 = ((fendaFieldSite.Kind == 1) ? 2 : 3);
						for (int num7 = 0; num7 < num6; num7++)
						{
							float num8 = (fendaFieldSite.Yaw + (float)(num7 * 137)) * ((float)Math.PI / 180f);
							float x = fendaFieldSite.X + Mathf.Cos(num8) * 2.1f;
							float z = fendaFieldSite.Z + Mathf.Sin(num8) * 2.1f;
							FendaImportedProp("VilaFenda_Campo_Rocha_" + k + "_" + num7, array[(k + num7) % 3], x, z, (num7 == 0) ? (3.4f + (float)(k % 3) * 0.7f) : (1.4f + (float)num7 * 0.45f), fendaFieldSite.Yaw + (float)(num7 * 53), array2[(k + num7) % 3], upright: false);
						}
					}
					num++;
					num2 += _roomRoot.transform.childCount - childCount;
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("[FendaCampo] Falha grupo" + k + ": " + ex));
				}
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[FendaCampo] PRONTO:" + num + "/32grupos," + num2 + "objetos;rochas/troncos/suprimentos SOLIDOS,apoio real,sem loot;reservas combate/trilha preservadas."));
		}

		private bool FendaFieldSiteClear(Vector3 foot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(foot + Vector3.up * 2f, 6f, -1, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Component)val).transform.IsChildOf(_roomRoot.transform) && !_fendaGround.Contains(val))
				{
					return false;
				}
			}
			return true;
		}

		internal static int FendaPavingKind(float x, float z)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(x, z);
			Vector2 val2 = val - new Vector2(0f, 10f);
			float num = Mathf.Atan2(val2.y, val2.x);
			float num2 = 9.8f + 0.5f * Mathf.Sin(num * 3f) + 0.2f * Mathf.Sin(num * 7f);
			if (((Vector2)(ref val2)).magnitude < num2)
			{
				return 2;
			}
			Vector4[] fendaPaths = FendaPaths;
			Vector2 val4 = default(Vector2);
			foreach (Vector4 val3 in fendaPaths)
			{
				((Vector2)(ref val4))..ctor(val3.x, val3.y);
				Vector2 val5 = new Vector2(val3.z, val3.w) - val4;
				float num3 = Mathf.Clamp01(Vector2.Dot(val - val4, val5) / ((Vector2)(ref val5)).sqrMagnitude);
				if (Vector2.Distance(val, val4 + val5 * num3) < 2.1f)
				{
					return 1;
				}
			}
			return 0;
		}

		private static float FendaPavingDistance(Vector2 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = point - new Vector2(0f, 10f);
			float num = Mathf.Atan2(val.y, val.x);
			float num2 = ((Vector2)(ref val)).magnitude - (9.8f + 0.5f * Mathf.Sin(num * 3f) + 0.2f * Mathf.Sin(num * 7f));
			Vector4[] fendaPaths = FendaPaths;
			Vector2 val3 = default(Vector2);
			foreach (Vector4 val2 in fendaPaths)
			{
				((Vector2)(ref val3))..ctor(val2.x, val2.y);
				Vector2 val4 = new Vector2(val2.z, val2.w) - val3;
				float num3 = Mathf.Clamp01(Vector2.Dot(point - val3, val4) / ((Vector2)(ref val4)).sqrMagnitude);
				num2 = Mathf.Min(num2, Vector2.Distance(point, val3 + val4 * num3) - 2.1f);
			}
			return num2;
		}

		private void CreateFendaRoads(Material plaza, Material path)
		{
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Expected O, but got Unknown
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: 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_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			List<int> list4 = new List<int>();
			Dictionary<Vector2, int> dictionary = new Dictionary<Vector2, int>();
			Vector2 val3 = default(Vector2);
			for (int i = -34; i < 49; i++)
			{
				for (int j = -46; j < 47; j++)
				{
					Vector2[] array = (Vector2[])(object)new Vector2[4]
					{
						new Vector2((float)j, (float)i),
						new Vector2((float)j, (float)(i + 1)),
						new Vector2((float)(j + 1), (float)(i + 1)),
						new Vector2((float)(j + 1), (float)i)
					};
					List<Vector2> list5 = new List<Vector2>();
					for (int k = 0; k < 4; k++)
					{
						Vector2 val = array[k];
						Vector2 val2 = array[(k + 1) % 4];
						float num = FendaPavingDistance(val);
						float num2 = FendaPavingDistance(val2);
						if (num <= 0f)
						{
							list5.Add(val);
						}
						if (num <= 0f != num2 <= 0f)
						{
							list5.Add(Vector2.Lerp(val, val2, num / (num - num2)));
						}
					}
					if (list5.Count < 3)
					{
						continue;
					}
					int[] array2 = new int[list5.Count];
					for (int l = 0; l < list5.Count; l++)
					{
						((Vector2)(ref val3))..ctor(Mathf.Round(list5[l].x * 10000f) / 10000f, Mathf.Round(list5[l].y * 10000f) / 10000f);
						if (!dictionary.TryGetValue(val3, out var value))
						{
							value = list.Count;
							dictionary.Add(val3, value);
							Vector3 val4 = FendaPoint(val3.x, val3.y) - (RoomCenter + FendaLocal);
							list.Add(val4 + Vector3.up * 0.06f);
							list2.Add(val3 / 3f);
						}
						array2[l] = value;
					}
					List<int> list6 = ((FendaPavingKind((float)j + 0.5f, (float)i + 0.5f) == 2) ? list4 : list3);
					for (int m = 1; m < array2.Length - 1; m++)
					{
						Vector3 val5 = list[array2[0]];
						Vector3 val6 = list[array2[m]];
						Vector3 val7 = list[array2[m + 1]];
						if (!(Vector3.Cross(val6 - val5, val7 - val5).y < 1E-06f))
						{
							list6.Add(array2[0]);
							list6.Add(array2[m]);
							list6.Add(array2[m + 1]);
						}
					}
				}
			}
			Mesh val8 = Own<Mesh>(new Mesh
			{
				name = "VilaFenda_Pavimento_Unico_Mesh"
			});
			val8.SetVertices(list);
			val8.SetUVs(0, list2);
			val8.subMeshCount = 2;
			val8.SetTriangles(list3, 0);
			val8.SetTriangles(list4, 1);
			val8.RecalculateNormals();
			val8.RecalculateTangents();
			val8.RecalculateBounds();
			GameObject val9 = new GameObject("VilaFenda_Pavimento_Unico");
			val9.transform.SetParent(_roomRoot.transform, true);
			val9.transform.position = RoomCenter + FendaLocal;
			val9.AddComponent<MeshFilter>().sharedMesh = val8;
			((Renderer)val9.AddComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[2] { path, plaza };
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[VilaFenda] Pavimento conectado:" + list.Count + "vertices;sem faces sobrepostas/colisor extra,segue piso real."));
		}

		private GameObject FendaMesh(string name, Vector3 origin, List<Vector3> vertices, List<Vector2> uv, List<int> faces, Material material, bool solid)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = Own<Mesh>(new Mesh
			{
				name = name + "_Mesh"
			});
			val.SetVertices(vertices);
			val.SetUVs(0, uv);
			val.SetTriangles(faces, 0);
			val.RecalculateNormals();
			val.RecalculateTangents();
			val.RecalculateBounds();
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(_roomRoot.transform, true);
			val2.transform.position = origin;
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = material;
			if (solid)
			{
				val2.AddComponent<MeshCollider>().sharedMesh = val;
			}
			return val2;
		}

		private void CreateFendaRuins(Material stone, Material trim)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 val = RoomCenter + FendaLocal;
			CreateFendaTower(stone);
			for (int i = 0; i < 2; i++)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[13];
				for (int j = 0; j < array.Length; j++)
				{
					float num = ((i == 0) ? (-39f + (float)j * 1.5f) : (32f + Mathf.Sin((float)j * 0.3f) * 2f));
					float num2 = ((i == 0) ? (22f + Mathf.Sin((float)j * 0.35f) * 2f) : (-4f + (float)j * 1.4f));
					array[j] = new Vector3(num, FendaPoint(num, num2).y - val.y - 0.12f, num2);
				}
				CreateErodedWall("VilaFenda_Muro_Roto_" + i, val, array, 2.4f, trim, null, 38120 + i);
			}
			Vector3 val2 = FendaPoint(0f, 10f);
			CreateJaggedIceMass("VilaFenda_Estatua_Pedestal", val2 - Vector3.up * 0.1f, 1.55f, 0.75f, trim, 38140);
			CreateFendaStatue(val2 + Vector3.up * 0.42f, stone);
			CreateSphere("VilaFenda_Estatua_Cabeca_Caida", FendaPoint(2.6f, 8.8f) + Vector3.up * 0.26f, new Vector3(0.64f, 0.55f, 0.72f), stone).transform.rotation = Quaternion.Euler(27f, 32f, -48f);
			for (int k = 0; k < 5; k++)
			{
				CreateJaggedIceMass("VilaFenda_Entulho_Torre_" + k, FendaPoint(-33f + (float)k * 1f, 30 - k % 2) - Vector3.up * 0.15f, 0.65f + (float)(k % 2) * 0.2f, 0.6f + (float)(k % 3) * 0.18f, stone, 38160 + k);
			}
			Vector3 val3 = FendaPoint(38f, 43f);
			for (int l = -1; l <= 1; l += 2)
			{
				CreateJaggedIceMass("VilaFenda_Caverna_Pilar_" + l, FendaPoint(38f + (float)l * 4.8f, 43f) - Vector3.up * 0.2f, 3.2f, 6.5f, stone, 38200 + l);
			}
			CreateJaggedIceMass("VilaFenda_Caverna_Arco", val3 + Vector3.up * 3.8f, 5.3f, 2.9f, trim, 38205);
			CreateJaggedIceMass("VilaFenda_Caverna_Selada", FendaPoint(38f, 44f) - Vector3.up * 0.2f, 4f, 4.8f, stone, 38206);
		}

		private void CreateFendaTower(Material stone)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_017d: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02b3: 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_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = RoomCenter + FendaLocal;
			Vector3[][] array = new Vector3[41][];
			Vector3 val2 = default(Vector3);
			Vector3 val3 = default(Vector3);
			for (int i = 0; i < 41; i++)
			{
				float num = -60f + (float)i * 300f / 40f;
				float num2 = num * ((float)Math.PI / 180f);
				float num3 = 3.7f * (1f + 0.055f * Mathf.Sin(num2 * 3f) + 0.03f * Mathf.Cos(num2 * 5f));
				((Vector3)(ref val2))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2));
				((Vector3)(ref val3))..ctor(-34f + val2.x * num3, 0f, 37f + val2.z * num3);
				val3.y = FendaPoint(val3.x, val3.z).y - val.y - 0.18f;
				float num4 = 3.8f * Mathf.Exp(0f - Mathf.Pow((num - 65f) / 38f, 2f));
				float num5 = 10.6f + 0.9f * Mathf.Sin(num2 * 2f) + 0.35f * Mathf.Sin(num2 * 7f) - num4;
				if (i < 3 || i > 37)
				{
					num5 -= 2f * (1f - (float)Mathf.Min(i, 40 - i) / 3f);
				}
				array[i] = (Vector3[])(object)new Vector3[4]
				{
					val3 - val2 * 0.5f,
					val3 + val2 * 0.5f,
					val3 + val2 * 0.5f + Vector3.up * num5,
					val3 - val2 * 0.5f + Vector3.up * num5
				};
			}
			List<Vector3> vertices = new List<Vector3>();
			List<Vector2> uv = new List<Vector2>();
			List<int> list = new List<int>();
			for (int j = 0; j < 40; j++)
			{
				Vector3 inside = (array[j][0] + array[j][1] + array[j][2] + array[j][3] + array[j + 1][0] + array[j + 1][1] + array[j + 1][2] + array[j + 1][3]) / 8f;
				for (int k = 0; k < 4; k++)
				{
					int num6 = (k + 1) % 4;
					AddSceneryFace(vertices, uv, list, (Vector3[])(object)new Vector3[4]
					{
						array[j][k],
						array[j + 1][k],
						array[j + 1][num6],
						array[j][num6]
					}, inside);
				}
			}
			AddSceneryFace(vertices, uv, list, array[0], (array[1][0] + array[1][2]) * 0.5f);
			AddSceneryFace(vertices, uv, list, array[40], (array[39][0] + array[39][2]) * 0.5f);
			FendaMesh("VilaFenda_Torre_Partida", val, vertices, uv, list, stone, solid: true);
		}

		private void CreateFendaStatue(Vector3 origin, Material stone)
		{
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[6] { 0f, 0.7f, 1.55f, 2.25f, 2.62f, 2.82f };
			float[] array2 = new float[6] { 0.62f, 0.52f, 0.43f, 0.72f, 0.52f, 0.24f };
			Vector3[][] array3 = new Vector3[array.Length][];
			for (int i = 0; i < array3.Length; i++)
			{
				array3[i] = (Vector3[])(object)new Vector3[16];
				for (int j = 0; j < 16; j++)
				{
					float num = (float)j * (float)Math.PI * 2f / 16f;
					float num2 = 1f + 0.1f * Mathf.Sin(num * 7f + (float)i * 0.5f);
					array3[i][j] = new Vector3(Mathf.Cos(num) * array2[i] * num2, array[i] + ((i == 5) ? (Mathf.Sin(num * 3f) * 0.12f) : 0f), Mathf.Sin(num) * array2[i] * 0.7f * num2);
				}
			}
			List<Vector3> vertices = new List<Vector3>();
			List<Vector2> uv = new List<Vector2>();
			List<int> list = new List<int>();
			for (int k = 0; k < array3.Length - 1; k++)
			{
				for (int l = 0; l < 16; l++)
				{
					int num3 = (l + 1) % 16;
					AddSceneryFace(vertices, uv, list, (Vector3[])(object)new Vector3[4]
					{
						array3[k][l],
						array3[k + 1][l],
						array3[k + 1][num3],
						array3[k][num3]
					}, Vector3.up * (array[k] + array[k + 1]) * 0.5f);
				}
			}
			AddSceneryFace(vertices, uv, list, array3[0], Vector3.up);
			AddSceneryFace(vertices, uv, list, array3[^1], Vector3.up * 2f);
			FendaMesh("VilaFenda_Estatua_Sem_Cabeca", origin, vertices, uv, list, stone, solid: true);
		}

		private void CreateFendaCrystals()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			Material[] array = (Material[])(object)new Material[3]
			{
				CreateMaterial(new Color(0.12f, 0.39f, 0.36f), new Color(0.04f, 0.28f, 0.23f)),
				CreateMaterial(new Color(0.31f, 0.48f, 0.58f), new Color(0.06f, 0.17f, 0.28f)),
				CreateMaterial(new Color(0.48f, 0.4f, 0.23f), new Color(0.28f, 0.13f, 0.03f))
			};
			Material[] array2 = array;
			foreach (Material val in array2)
			{
				if (val.HasProperty("_Glossiness"))
				{
					val.SetFloat("_Glossiness", 0.62f);
				}
			}
			for (int j = 0; j < FendaCrystalLots.Length; j++)
			{
				Vector2 val2 = FendaCrystalLots[j];
				for (int k = 0; k < 3 + j % 2; k++)
				{
					float num = (float)k * 2.1f + (float)j * 0.73f;
					float x = val2.x + Mathf.Cos(num) * 0.8f;
					float z = val2.y + Mathf.Sin(num) * 0.8f;
					CreateIceSpike("VilaFenda_Cristal_" + j + "_" + k, FendaPoint(x, z) - Vector3.up * 0.08f, 0.22f + (float)k * 0.08f, 1f + (float)((j + k) % 4) * 0.6f, new Vector3(Mathf.Cos(num) * 0.2f, 1f, Mathf.Sin(num) * 0.2f), array[(j + k) % array.Length], 38300 + j * 5 + k);
				}
			}
		}

		private void CreateFendaNature(Material stone)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: 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_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: 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_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: 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_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets", "OrganicWinter");
			Material val = CreateMaterial(new Color(0.76f, 0.72f, 0.64f), Color.black);

BepInEx/plugins/Codex_Salto_Tempestade/CodexSaltoTempestade.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexHumanoidExtras;
using CodexSkillIcons;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexSkillIcons
{
	internal static class SkillIcon
	{
		private static readonly HashSet<Sprite> owned = new HashSet<Sprite>();

		internal static Sprite Load(string folder, Func<Sprite> fallback, Action<string> warning)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = null;
			Sprite val2 = null;
			try
			{
				val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					name = "Codex_SkillIcon_Painted",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)2
				};
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, "UI", "skill-icon.png")), false) || ((Texture)val).width != 512 || ((Texture)val).height != 512)
				{
					throw new InvalidDataException("Expected512x512 skill-icon.png");
				}
				val.Apply(true, true);
				val2 = Sprite.Create(val, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidDataException("Icon Sprite unavailable");
				}
				owned.Add(val2);
				return val2;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				warning?.Invoke("ICON_FALLBACK:" + ex.Message);
				return fallback();
			}
		}

		internal static void Release(Sprite sprite)
		{
			if (!((Object)(object)sprite == (Object)null) && owned.Remove(sprite))
			{
				Object.Destroy((Object)(object)sprite.texture);
				Object.Destroy((Object)(object)sprite);
			}
		}
	}
}
namespace CodexSaltoTempestade
{
	[BepInPlugin("codex.outward.salto.tempestade", "Codex - Salto da Tempestade", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.salto.tempestade";

		public const int SkillId = 9106930;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = SkillIcon.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (Func<Sprite>)TempestVisual.CreateIcon, (Action<string>)Log.LogWarning);
			patches = new Harmony("codex.outward.salto.tempestade");
			patches.PatchAll(typeof(Plugin).Assembly);
			TempestVisual.Paused = delegate
			{
				NetworkLevelLoader instance = NetworkLevelLoader.Instance;
				return instance != null && instance.IsGameplayPaused;
			};
			SL_Item.AddOnInstanceStartListener(9106930, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[SaltoTempestade] 1.0.5;treinador;cooldown40s;NinjaJump/+2m/buff/combat unchanged");
		}

		private void Build()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				TempestClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				TempestVisual.Ensure(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				try
				{
					TempestBuff.Build(icon);
				}
				catch (Exception ex)
				{
					Log.LogError((object)("[SaltoTempestade] BUFF_INITFAILED;approved jump retained:" + ex));
				}
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106930) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106930);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106930;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Salto da Tempestade";
				((SL_Item)val2).Description = "Salto visual com NinjaJump externo. Na aterrissagem libera raios azuis:120 dano eletrico,40 impacto,raio6m. Depois da explosao:+30% de velocidade de movimento por30s,com aura azul. Nao acumula.30vigor,40s recarga. Requer espada1H/2H. Nao salta obstaculos.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 30f;
				((SL_Skill)val2).Cooldown = 40f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[2]
				{
					default(WeaponType),
					(WeaponType)51
				};
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[SaltoTempestade] PRONTO:9106930;Salto da Tempestade;Human=True;NinjaJump sequence;30vigor/40s;visual USER APPROVED");
			}
			catch (Exception ex2)
			{
				Log.LogError((object)("[SaltoTempestade] INITFAILED:" + ex2));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106930)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			TempestMotion boundMotion = null;
			TempestBuffController boundBuff = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || (Object)(object)boundBuff == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					boundBuff = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								TempestBuffController tempestBuffController = ((Component)value).GetComponent<TempestBuffController>();
								if ((Object)(object)tempestBuffController == (Object)null)
								{
									tempestBuffController = ((Component)value).gameObject.AddComponent<TempestBuffController>();
									tempestBuffController.Bind(value);
								}
								TempestMotion tempestMotion = ((Component)value).GetComponent<TempestMotion>();
								if ((Object)(object)tempestMotion == (Object)null)
								{
									try
									{
										tempestMotion = ((Component)value).gameObject.AddComponent<TempestMotion>();
										tempestMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)tempestMotion != (Object)null)
										{
											Object.Destroy((Object)(object)tempestMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[SaltoTempestade] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = tempestMotion;
								boundBuff = tempestBuffController;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			TempestMotion[] array = Object.FindObjectsOfType<TempestMotion>();
			foreach (TempestMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			TempestBuffController[] array2 = Object.FindObjectsOfType<TempestBuffController>();
			foreach (TempestBuffController obj2 in array2)
			{
				obj2.Shutdown();
				Object.Destroy((Object)(object)obj2);
			}
			TempestEffect[] array3 = Object.FindObjectsOfType<TempestEffect>();
			for (int i = 0; i < array3.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array3[i]).gameObject);
			}
			Harmony obj3 = patches;
			if (obj3 != null)
			{
				obj3.UnpatchAll("codex.outward.salto.tempestade");
			}
			TempestClip.Dispose();
			TempestVisual.Release();
			SkillIcon.Release(icon);
			if ((Object)(object)icon != (Object)null)
			{
				Object.Destroy((Object)(object)icon.texture);
				Object.Destroy((Object)(object)icon);
			}
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106930)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<TempestMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			TempestMotion component = ((Component)__instance).GetComponent<TempestMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106930)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter != null)
				{
					((Component)ownerCharacter).GetComponent<TempestMotion>()?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<TempestMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				TempestMotion tempestMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<TempestMotion>() : null);
				if (((Item)__instance).ItemID == 9106930)
				{
					__result = tempestMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && tempestMotion != null && tempestMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			TempestMotion component = ((Component)__instance).GetComponent<TempestMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class TempestAttack
	{
		internal const float Damage = 120f;

		internal const float Impact = 40f;

		internal const float Radius = 6f;

		internal static void Release(TempestMotion source, Character owner)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_013b: 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_0151: 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_017c: 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_019e: Expected O, but got Unknown
			Vector3 position = ((Component)owner).transform.position;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(position + Vector3.up * 1.5f, Vector3.down, ref val, 4f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
			{
				Plugin.Log.LogWarning((object)"[SaltoTempestade] NO_GROUND;no hit/VFX");
				return;
			}
			position = ((RaycastHit)(ref val)).point;
			TempestVisual.Burst(position + Vector3.up * 0.07f);
			HashSet<Character> hashSet = new HashSet<Character>();
			int num = 0;
			Collider[] array = Physics.OverlapSphere(position, 6f, LayerMask.GetMask(new string[1] { "Hitbox" }), (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox componentInParent = ((Component)array[i]).GetComponentInParent<Hitbox>();
				Character val2 = ((componentInParent != null) ? componentInParent.OwnerChar : null);
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)owner) && val2.Alive && !val2.IsLocalPlayer && !hashSet.Contains(val2) && !((Object)(object)owner.TargetingSystem == (Object)null) && owner.TargetingSystem.IsTargetable(val2))
				{
					Vector3 val3 = val2.CenterPosition - position;
					if (!(Mathf.Abs(val3.y) > 2.8f) && !Physics.Linecast(position + Vector3.up * 0.7f, val2.CenterPosition, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1))
					{
						hashSet.Add(val2);
						val2.ReceiveHit((Object)null, new DamageList((Types)3, 120f), ((Vector3)(ref val3)).normalized, val2.CenterPosition, 45f, 1f, owner, 40f, true);
						num++;
					}
				}
			}
			Plugin.Log.LogMessage((object)("[SaltoTempestade] LANDING;hits=" + num + ";120Electric/40impact;6m;unblockable ground special;single hit per target"));
			TempestBuffController.Landed(owner);
		}
	}
	internal static class TempestBuff
	{
		internal const string Identifier = "Codex.Tempestade.CargaAzul";

		internal const float Duration = 30f;

		internal const float SpeedPercent = 30f;

		private static StatusEffect prefab;

		internal static void Build(Sprite icon)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00f0: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			if (!((Object)(object)prefab != (Object)null))
			{
				if ((Object)(object)ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Codex.Tempestade.CargaAzul") != (Object)null)
				{
					throw new InvalidOperationException("Buff identifier occupied:Codex.Tempestade.CargaAzul");
				}
				SL_StatusEffect val = new SL_StatusEffect();
				val.TargetStatusIdentifier = "Defense Bonus";
				val.StatusIdentifier = "Codex.Tempestade.CargaAzul";
				val.Name = "Carga da Tempestade";
				val.Description = "+30% de velocidade de movimento durante 30 segundos.";
				val.Lifespan = 30f;
				val.DisplayedInHUD = true;
				val.IsHidden = false;
				val.IsMalusEffect = false;
				val.Purgeable = true;
				val.PlayFXOnActivation = false;
				val.PlaySpecialFXOnStop = false;
				val.Tags = new string[0];
				val.EffectBehaviour = (EditBehaviours)2;
				SL_EffectTransform[] array = new SL_EffectTransform[1];
				SL_EffectTransform val2 = new SL_EffectTransform();
				val2.TransformName = "Effects";
				val2.Effects = (SL_Effect[])(object)new SL_Effect[1] { (SL_Effect)new SL_AffectStat
				{
					Stat_Tag = "MovementSpeed",
					AffectQuantity = 30f,
					IsModifier = true
				} };
				array[0] = val2;
				val.Effects = (SL_EffectTransform[])(object)array;
				((ContentTemplate)val).ApplyTemplate();
				prefab = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Codex.Tempestade.CargaAzul");
				if ((Object)(object)prefab == (Object)null || prefab.StatusData == null || prefab.StatusData.LifeSpan != 30f)
				{
					throw new InvalidOperationException("Temporary speed buff creation failed");
				}
				prefab.OverrideIcon = icon;
				Plugin.Log.LogMessage((object)"[SaltoTempestade] BUFF_READY;30percentMovementSpeed/30s;private status;no stacking");
			}
		}

		internal static bool Apply(Character owner)
		{
			if ((Object)(object)prefab == (Object)null || (Object)(object)owner == (Object)null || !owner.IsLocalPlayer || !owner.Alive || (Object)(object)owner.StatusEffectMngr == (Object)null)
			{
				return false;
			}
			owner.StatusEffectMngr.RemoveStatusWithIdentifierName("Codex.Tempestade.CargaAzul");
			if ((Object)(object)owner.StatusEffectMngr.AddStatusEffect(prefab, owner) == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[SaltoTempestade] BUFF_REJECTED;natively immune/unavailable");
				return false;
			}
			Plugin.Log.LogMessage((object)"[SaltoTempestade] BUFF_APPLIED;30percentMovementSpeed;30s;refreshed not stacked");
			return true;
		}

		internal static void Remove(Character owner)
		{
			if ((Object)(object)owner != (Object)null && (Object)(object)owner.StatusEffectMngr != (Object)null)
			{
				owner.StatusEffectMngr.RemoveStatusWithIdentifierName("Codex.Tempestade.CargaAzul");
			}
		}
	}
	public sealed class TempestBuffController : MonoBehaviour
	{
		private Character owner;

		private GameObject aura;

		private readonly TempestBuffDelay delay = new TempestBuffDelay();

		internal void Bind(Character value)
		{
			owner = value;
		}

		internal static void Landed(Character value)
		{
			if (!((Object)(object)value == (Object)null) && value.IsLocalPlayer && value.Alive)
			{
				TempestBuffController tempestBuffController = ((Component)value).GetComponent<TempestBuffController>();
				if ((Object)(object)tempestBuffController == (Object)null)
				{
					tempestBuffController = ((Component)value).gameObject.AddComponent<TempestBuffController>();
					tempestBuffController.Bind(value);
				}
				tempestBuffController.delay.Schedule();
			}
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive)
			{
				delay.Cancel();
				StopAura();
				TempestBuff.Remove(owner);
			}
			else if ((Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				delay.Cancel();
				StopAura();
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				try
				{
					if (delay.Tick(Time.deltaTime, paused: false))
					{
						TempestBuff.Apply(owner);
					}
					StatusEffectManager statusEffectMngr = owner.StatusEffectMngr;
					StatusEffect val = ((statusEffectMngr != null) ? statusEffectMngr.GetStatusEffectOfName("Codex.Tempestade.CargaAzul") : null);
					if ((Object)(object)val == (Object)null || !val.IsActive)
					{
						StopAura();
					}
					else if ((Object)(object)aura == (Object)null)
					{
						Animator animator = owner.Animator;
						Transform val2 = ((animator != null) ? animator.GetBoneTransform((HumanBodyBones)0) : null);
						if ((Object)(object)val2 != (Object)null)
						{
							aura = TempestVisual.ChargedAura(val2);
						}
					}
				}
				catch (Exception ex)
				{
					delay.Cancel();
					StopAura();
					Plugin.Log.LogError((object)("[SaltoTempestade] BUFF_FAILED:" + ex));
				}
			}
		}

		private void StopAura()
		{
			if ((Object)(object)aura != (Object)null)
			{
				Object.Destroy((Object)(object)aura);
				aura = null;
			}
		}

		internal void Shutdown()
		{
			delay.Cancel();
			StopAura();
			TempestBuff.Remove(owner);
		}

		private void OnDisable()
		{
			delay.Cancel();
			StopAura();
		}

		private void OnDestroy()
		{
			delay.Cancel();
			StopAura();
		}
	}
	internal sealed class TempestBuffDelay
	{
		internal const float BurstDuration = 0.7f;

		private float remaining;

		private bool pending;

		internal void Schedule()
		{
			remaining = 0.7f;
			pending = true;
		}

		internal bool Tick(float delta, bool paused)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			if (!pending || paused)
			{
				return false;
			}
			remaining -= delta;
			if (remaining > 1E-05f)
			{
				return false;
			}
			pending = false;
			return true;
		}

		internal void Cancel()
		{
			pending = false;
		}
	}
	internal static class TempestClip
	{
		internal const string Prefix = "SaltoTempestadeHumanoid_";

		internal const float Duration = 2.3666668f;

		internal const string Hash = "0855047F26086BEF10859AB997D0DCD58A7C5433BA8801BE4B3382B6AAE00F53";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_salto_tempestade");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "0855047F26086BEF10859AB997D0DCD58A7C5433BA8801BE4B3382B6AAE00F53")
					{
						throw new InvalidDataException("Compiled NinjaJump SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled NinjaJump bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexTempestade_NinjaJump");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 2.3666668f) > 0.001f)
				{
					throw new InvalidDataException("Expected official external Humanoid NinjaJump");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "SaltoTempestadeHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	internal static class TempestLiftCurve
	{
		internal const float Height = 2f;

		internal const float Start = 0.056338027f;

		internal const float Peak = 0.1971831f;

		internal const float Descent = 0.36619717f;

		internal const float Land = 0.5492958f;

		internal static float At(float progress)
		{
			if (float.IsNaN(progress) || float.IsInfinity(progress) || progress <= 0.056338027f || progress >= 0.5492958f)
			{
				return 0f;
			}
			if (progress < 0.1971831f)
			{
				return 2f * Smooth((progress - 0.056338027f) / 0.14084508f);
			}
			if (progress <= 0.36619717f)
			{
				return 2f;
			}
			return 2f * (1f - Smooth((progress - 0.36619717f) / 0.18309861f));
		}

		private static float Smooth(float t)
		{
			return t * t * (3f - 2f * t);
		}
	}
	internal sealed class TempestLiftLease
	{
		private readonly Transform root;

		private readonly Transform parent;

		private Vector3 offset;

		private Vector3 written;

		private bool applied;

		internal TempestLiftLease(Transform visual, Transform character)
		{
			if ((Object)(object)visual == (Object)null || (Object)(object)character == (Object)null || (Object)(object)visual == (Object)(object)character || !visual.IsChildOf(character) || (Object)(object)visual.parent == (Object)null)
			{
				throw new InvalidOperationException("Lift requires a separate child visual container");
			}
			root = visual;
			parent = visual.parent;
		}

		internal bool Apply(float height)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Remove();
			if ((Object)(object)root == (Object)null || (Object)(object)root.parent != (Object)(object)parent || float.IsNaN(height) || float.IsInfinity(height) || height < 0f || height > 2f)
			{
				return false;
			}
			if (height == 0f)
			{
				return true;
			}
			offset = parent.InverseTransformVector(Vector3.up * height);
			written = root.localPosition + offset;
			root.localPosition = written;
			applied = true;
			return true;
		}

		internal void Remove()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (applied)
			{
				if ((Object)(object)root != (Object)null && (Object)(object)root.parent == (Object)(object)parent && Math.Abs(Vector3.Dot(root.localPosition - written, offset)) < 1E-06f)
				{
					Transform obj = root;
					obj.localPosition -= offset;
				}
				applied = false;
				offset = Vector3.zero;
			}
		}
	}
	[DefaultExecutionOrder(10000)]
	public sealed class TempestMotion : MonoBehaviour
	{
		private Character player;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private TempestTimeline clock;

		private bool nativeCast;

		private float normalized;

		private GameObject aura;

		private TempestLiftLease lift;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (TempestClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding && (Object)(object)player.CharacterController != (Object)null && ((Collider)player.CharacterController).enabled && (Object)(object)player.Animator.avatar == (Object)(object)avatar)
				{
					return ValidVisualRoot();
				}
				return false;
			}
		}

		private bool ValidVisualRoot()
		{
			Transform visualHolderTrans = player.VisualHolderTrans;
			Transform boneTransform = player.Animator.GetBoneTransform((HumanBodyBones)0);
			if ((Object)(object)visualHolderTrans != (Object)null && (Object)(object)visualHolderTrans != (Object)(object)((Component)player).transform && (Object)(object)visualHolderTrans != (Object)(object)((Component)player.Animator).transform && (Object)(object)visualHolderTrans.parent != (Object)null && visualHolderTrans.IsChildOf(((Component)player).transform) && (Object)(object)boneTransform != (Object)null && (Object)(object)boneTransform != (Object)(object)visualHolderTrans)
			{
				return boneTransform.IsChildOf(visualHolderTrans);
			}
			return false;
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				TempestClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			if (((Item)value).ItemID != 9106930 || !CanBegin)
			{
				return false;
			}
			try
			{
				lift = new TempestLiftLease(player.VisualHolderTrans, ((Component)player).transform);
				lease.Acquire(TempestClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new TempestTimeline();
				nativeCast = false;
				normalized = 0f;
				Plugin.Log.LogMessage((object)"[SaltoTempestade] CAST;NinjaJump;30vigor/12s;visualLift2m;capsuleGrounded;AvatarUNCHANGED");
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && (Object)(object)value == (Object)(object)skill && !tail.NativeEnded)
			{
				tail.EndNative();
			}
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if (instance == null || !instance.IsGameplayPaused)
			{
				lift?.Remove();
			}
		}

		private void LateUpdate()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (flag)
				{
					try
					{
						clock.Observe(normalized);
						if (!ValidVisualRoot() || !lift.Apply(TempestLiftCurve.At(normalized)))
						{
							Fail("Visual container lost/reparented");
							return;
						}
						if (clock.Started && !nativeCast)
						{
							if (!OwnCast)
							{
								Fail("Receiver lost before cost");
								return;
							}
							NativeInvocation = true;
							nativeCast = true;
							((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
							NativeInvocation = false;
							if (!Active || !OwnCast)
							{
								return;
							}
							aura = TempestVisual.Aura(player.Animator.GetBoneTransform((HumanBodyBones)0) ?? ((Component)player).transform);
						}
						if (clock.TryStrike() && nativeCast)
						{
							if ((Object)(object)aura != (Object)null)
							{
								Object.Destroy((Object)(object)aura);
								aura = null;
							}
							TempestAttack.Release(this, player);
						}
					}
					catch (Exception ex)
					{
						Fail("RELEASEFAILED:" + ex);
						return;
					}
					finally
					{
						NativeInvocation = false;
					}
				}
				if (tail.CanRestore)
				{
					Cancel("native blend-out complete");
				}
				else if (tail.TimedOut(2.3666668f))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("SaltoTempestadeHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[SaltoTempestade] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			lift?.Remove();
			lift = null;
			clock?.Cancel();
			bool active = Active;
			skill = null;
			tail = null;
			clock = null;
			bool flag = (NativeInvocation = false);
			nativeCast = flag;
			if ((Object)(object)aura != (Object)null)
			{
				Object.Destroy((Object)(object)aura);
				aura = null;
			}
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[SaltoTempestade] RESTORED;" + reason));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[SaltoTempestade] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal sealed class TempestTimeline
	{
		internal const float StartAt = 0.056338027f;

		internal const float StrikeAt = 0.57746476f;

		private float progress;

		private bool released;

		private bool cancelled;

		internal bool Started
		{
			get
			{
				if (!cancelled)
				{
					return progress >= 0.056338027f;
				}
				return false;
			}
		}

		internal void Observe(float value)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, value);
			}
		}

		internal bool TryStrike()
		{
			if (cancelled || released || progress < 0.57746476f)
			{
				return false;
			}
			released = true;
			return true;
		}

		internal void Cancel()
		{
			cancelled = true;
		}
	}
	internal static class TempestVisual
	{
		internal static Func<bool> Paused;

		internal static Material Arc;

		internal static Material Ring;

		internal static Texture2D[] Frames;

		internal static Mesh Annulus;

		private static Texture2D lightning;

		internal static void Ensure(string folder)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//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_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Arc != (Object)null)
			{
				return;
			}
			try
			{
				Shader val = Shader.Find("Legacy Shaders/Particles/Additive");
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Additive shader unavailable;opaque fallback forbidden");
				}
				lightning = Load(Path.Combine(folder, "Assets", "lightning.png"), (TextureWrapMode)0);
				if (((Texture)lightning).width != 2048 || ((Texture)lightning).height != 512)
				{
					throw new InvalidDataException("Lightning texture must be 2K2048x512");
				}
				Arc = new Material(val)
				{
					name = "Tempestade_SharedLightning",
					mainTexture = (Texture)(object)lightning
				};
				Arc.SetColor("_TintColor", new Color(0.35f, 0.7f, 1f, 0.8f));
				Frames = (Texture2D[])(object)new Texture2D[19];
				for (int i = 0; i < Frames.Length; i++)
				{
					Frames[i] = Load(Path.Combine(folder, "Assets", "Blue Ring Explosion" + (i + 1) + ".png"), (TextureWrapMode)1);
				}
				Ring = new Material(val)
				{
					name = "Tempestade_SharedRing",
					mainTexture = (Texture)(object)Frames[0]
				};
				Ring.SetColor("_TintColor", new Color(0.25f, 0.65f, 1f, 0.7f));
				Vector3[] array = (Vector3[])(object)new Vector3[130];
				Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
				int[] array3 = new int[384];
				for (int j = 0; j <= 64; j++)
				{
					for (int k = 0; k < 2; k++)
					{
						float num = (float)(j * 2) * (float)Math.PI / 64f;
						float num2 = ((k == 0) ? 0.66f : 1f);
						int num3 = j * 2 + k;
						array[num3] = new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
						array2[num3] = new Vector2(0.5f + array[num3].x * 0.5f, 0.5f + array[num3].z * 0.5f);
					}
				}
				for (int l = 0; l < 64; l++)
				{
					int num4 = l * 6;
					int num5 = (array3[num4] = l * 2);
					array3[num4 + 1] = num5 + 2;
					array3[num4 + 2] = num5 + 1;
					array3[num4 + 3] = num5 + 1;
					array3[num4 + 4] = num5 + 2;
					array3[num4 + 5] = num5 + 3;
				}
				Annulus = new Mesh
				{
					name = "Tempestade_SharedAnnulus",
					vertices = array,
					uv = array2,
					triangles = array3
				};
				Annulus.RecalculateBounds();
			}
			catch
			{
				Release();
				throw;
			}
		}

		private static Texture2D Load(string path, TextureWrapMode wrap)
		{
			//IL_0004: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = Path.GetFileNameWithoutExtension(path),
				filterMode = (FilterMode)2,
				wrapMode = wrap
			};
			try
			{
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path), true))
				{
					throw new InvalidDataException("PNG invalid:" + path);
				}
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		internal static LineRenderer Line(Transform parent, Vector3[] points, float width)
		{
			//IL_0005: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			GameObject val = new GameObject("Tempestade_Arc");
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			((Renderer)obj).sharedMaterial = Arc;
			obj.useWorldSpace = false;
			obj.widthMultiplier = width;
			obj.positionCount = points.Length;
			obj.SetPositions(points);
			Color startColor = (obj.endColor = Color.white);
			obj.startColor = startColor;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			obj.textureMode = (LineTextureMode)0;
			return obj;
		}

		internal static GameObject Aura(Transform parent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Tempestade_AirAura");
			val.transform.SetParent(parent, false);
			for (int i = 0; i < 4; i++)
			{
				((Component)Line(val.transform, (Vector3[])(object)new Vector3[3]
				{
					new Vector3(-0.45f, -0.1f, 0f),
					new Vector3(0f, 0.35f, 0.08f),
					new Vector3(0.45f, 0.15f, 0f)
				}, 0.24f)).transform.localRotation = Quaternion.Euler((float)(i * 37), (float)(45 + i * 90), (float)(i * 23));
			}
			val.AddComponent<TempestEffect>().Configure(inAir: true);
			return val;
		}

		internal static GameObject Burst(Vector3 center)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Tempestade_LandingBurst");
			val.transform.position = center;
			GameObject val2 = new GameObject("Tempestade_Ring");
			val2.transform.SetParent(val.transform, false);
			val2.AddComponent<MeshFilter>().sharedMesh = Annulus;
			MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
			((Renderer)val3).sharedMaterial = Ring;
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
			Vector3 val4 = default(Vector3);
			for (int i = 0; i < 10; i++)
			{
				float num = (float)(i * 2) * (float)Math.PI / 10f;
				((Vector3)(ref val4))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num));
				Line(val.transform, (Vector3[])(object)new Vector3[3]
				{
					val4 * 0.3f + Vector3.up * 0.14f,
					val4 * 2.4f + Vector3.up * 0.2f,
					val4 * 5.6f + Vector3.up * 0.13f
				}, 0.55f);
			}
			Line(val.transform, (Vector3[])(object)new Vector3[3]
			{
				Vector3.zero,
				Vector3.up * 1.4f + Vector3.right * 0.1f,
				Vector3.up * 3.8f
			}, 0.8f);
			TempestEffect tempestEffect = val.AddComponent<TempestEffect>();
			tempestEffect.Configure(inAir: false, val3);
			tempestEffect.SetTime(0.1f);
			return val;
		}

		internal static GameObject ChargedAura(Transform parent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Tempestade_ChargedAura");
			val.transform.SetParent(parent, false);
			for (int i = 0; i < 6; i++)
			{
				((Component)Line(val.transform, (Vector3[])(object)new Vector3[3]
				{
					new Vector3(-0.55f, -0.38f, 0f),
					new Vector3(0f, 0.15f, 0.14f),
					new Vector3(0.55f, 0.62f, 0f)
				}, 0.25f)).transform.localRotation = Quaternion.Euler((float)(i * 21), (float)(i * 60), (float)(i * 17));
			}
			val.AddComponent<TempestChargeVisual>();
			return val;
		}

		internal static Sprite CreateIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j - 31.5f) / 30f;
					float num2 = ((float)i - 31.5f) / 30f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					bool flag = i > 10 && i < 54 && Mathf.Abs((float)j - (35f - (float)i * 0.18f + (float)((i < 31) ? 8 : 0))) < 3f;
					array[i * 64 + j] = (Color)((num3 > 1f) ? Color.clear : (flag ? new Color(0.8f, 0.95f, 1f, 1f) : new Color(0.02f, 0.1f, 0.2f, 1f)));
				}
			}
			val.SetPixels(array);
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 64f);
		}

		internal static void Release()
		{
			if ((Object)(object)Arc != (Object)null)
			{
				Object.Destroy((Object)(object)Arc);
			}
			if ((Object)(object)Ring != (Object)null)
			{
				Object.Destroy((Object)(object)Ring);
			}
			if ((Object)(object)Annulus != (Object)null)
			{
				Object.Destroy((Object)(object)Annulus);
			}
			if ((Object)(object)lightning != (Object)null)
			{
				Object.Destroy((Object)(object)lightning);
			}
			if (Frames != null)
			{
				Texture2D[] frames = Frames;
				foreach (Texture2D val in frames)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
			Arc = (Ring = null);
			Annulus = null;
			Frames = null;
			lightning = null;
			Paused = null;
		}
	}
	public sealed class TempestChargeVisual : MonoBehaviour
	{
		private float age;

		internal void SetTime(float value)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localRotation = Quaternion.Euler(0f, value * 110f, 0f);
		}

		private void Update()
		{
			Func<bool> paused = TempestVisual.Paused;
			if (paused == null || !paused())
			{
				age += Time.deltaTime;
				SetTime(age);
			}
		}
	}
	public sealed class TempestEffect : MonoBehaviour
	{
		private bool aura;

		private float age;

		private LineRenderer[] arcs;

		private MeshRenderer ring;

		private MaterialPropertyBlock block;

		internal void Configure(bool inAir, MeshRenderer value = null)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			aura = inAir;
			ring = value;
			arcs = ((Component)this).GetComponentsInChildren<LineRenderer>();
			block = new MaterialPropertyBlock();
		}

		internal void SetTime(float time)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			if (arcs == null)
			{
				return;
			}
			if (aura)
			{
				((Component)this).transform.localRotation = Quaternion.Euler(0f, time * 180f, 0f);
				return;
			}
			float num = Mathf.Clamp01(time / 0.7f);
			float num2 = 1f - num;
			LineRenderer[] array = arcs;
			Color val = default(Color);
			foreach (LineRenderer obj in array)
			{
				((Color)(ref val))..ctor(1f, 1f, 1f, num2);
				Color startColor = (obj.endColor = val);
				obj.startColor = startColor;
			}
			if ((Object)(object)ring != (Object)null)
			{
				((Component)ring).transform.localScale = Vector3.one * Mathf.Lerp(0.8f, 6f, Mathf.Sqrt(num));
				block.SetTexture("_MainTex", (Texture)(object)TempestVisual.Frames[Mathf.Clamp((int)(num * 19f), 0, 18)]);
				block.SetColor("_TintColor", new Color(0.25f, 0.65f, 1f, num2 * 0.7f));
				((Renderer)ring).SetPropertyBlock(block);
			}
		}

		private void Update()
		{
			Func<bool> paused = TempestVisual.Paused;
			if (paused == null || !paused())
			{
				age += Time.deltaTime;
				SetTime(age);
				if (age > (aura ? 4f : 0.7f))
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}
	}
}

BepInEx/plugins/Codex_Sapo_Brejo/CodexSapoBrejo.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CodexCombat;
using CodexSwamp;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexSwamp
{
	internal static class PoisonOnHit
	{
		internal static void Apply(Character source, Character target, StatusEffect poison, bool blocked)
		{
			if (!blocked && !((Object)(object)target == (Object)null) && target.Alive && !((Object)(object)poison == (Object)null) && !((Object)(object)target.StatusEffectMngr == (Object)null))
			{
				target.StatusEffectMngr.AddStatusEffect(poison, source);
			}
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexSapoBrejo
{
	[DataContract]
	internal sealed class FrogFrame
	{
		[DataMember(IsRequired = true)]
		public float[] xyz;
	}
	[DataContract]
	internal sealed class FrogClip
	{
		[DataMember(IsRequired = true)]
		public string name;

		[DataMember(IsRequired = true)]
		public float fps;

		[DataMember(IsRequired = true)]
		public FrogFrame[] frames;
	}
	[DataContract]
	internal sealed class FrogAsset
	{
		[DataMember(IsRequired = true)]
		public int schema;

		[DataMember(IsRequired = true)]
		public int[] triangles;

		[DataMember(IsRequired = true)]
		public float[] uv;

		[DataMember(IsRequired = true)]
		public FrogClip[] clips;

		[DataMember(IsRequired = true)]
		public float[] mouth;

		[DataMember(IsRequired = true)]
		public float length;
	}
	internal static class FrogAssetReader
	{
		internal static FrogAsset Read(string path)
		{
			FileInfo fileInfo = new FileInfo(path);
			if (!fileInfo.Exists || fileInfo.Length < 64 || fileInfo.Length > 10485760)
			{
				throw new InvalidDataException("Asset inexistente ou fora do limite10MB:" + path);
			}
			using FileStream stream = File.OpenRead(path);
			return Read(stream);
		}

		internal static FrogAsset Read(Stream stream)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			FrogAsset obj = (FrogAsset)((XmlObjectSerializer)new DataContractJsonSerializer(typeof(FrogAsset), (IEnumerable<Type>)null, 1000000, false, (IDataContractSurrogate)null, false)).ReadObject(stream);
			Validate(obj);
			return obj;
		}

		private static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		internal static void Validate(FrogAsset data)
		{
			if (data == null || data.schema != 1)
			{
				throw new InvalidDataException("Schema do asset deve ser1");
			}
			if (data.uv == null || data.uv.Length % 2 != 0 || data.uv.Length < 6 || data.uv.Length > 20000)
			{
				throw new InvalidDataException("UV invalido");
			}
			int num = data.uv.Length / 2;
			if (data.triangles == null || data.triangles.Length % 3 != 0 || data.triangles.Length < 3 || data.triangles.Length > 30000)
			{
				throw new InvalidDataException("Triangulos invalidos");
			}
			int[] triangles = data.triangles;
			foreach (int num2 in triangles)
			{
				if (num2 < 0 || num2 >= num)
				{
					throw new InvalidDataException("Indice de triangulo fora da malha");
				}
			}
			float[] uv = data.uv;
			for (int i = 0; i < uv.Length; i++)
			{
				if (!Finite(uv[i]))
				{
					throw new InvalidDataException("UV nao finito");
				}
			}
			if (!Finite(data.length) || data.length <= 0f || data.length > 5f)
			{
				throw new InvalidDataException("Comprimento invalido");
			}
			if (data.mouth == null || data.mouth.Length != 3)
			{
				throw new InvalidDataException("Boca incompleta");
			}
			uv = data.mouth;
			foreach (float value in uv)
			{
				if (!Finite(value) || Math.Abs(value) > 5f)
				{
					throw new InvalidDataException("Boca fora dos limites");
				}
			}
			if (data.clips == null || data.clips.Length != 2)
			{
				throw new InvalidDataException("Sao necessarios idle e walk");
			}
			bool flag = false;
			bool flag2 = false;
			FrogClip[] clips = data.clips;
			foreach (FrogClip frogClip in clips)
			{
				if (frogClip == null || frogClip.frames == null || frogClip.frames.Length < 2 || frogClip.frames.Length > 60 || !Finite(frogClip.fps) || frogClip.fps < 1f || frogClip.fps > 30f)
				{
					throw new InvalidDataException("Clip/frame/fps invalido");
				}
				if (frogClip.name == "idle" && !flag)
				{
					flag = true;
				}
				else
				{
					if (!(frogClip.name == "walk") || flag2)
					{
						throw new InvalidDataException("Clip desconhecido ou duplicado:" + frogClip.name);
					}
					flag2 = true;
				}
				FrogFrame[] frames = frogClip.frames;
				foreach (FrogFrame frogFrame in frames)
				{
					if (frogFrame == null || frogFrame.xyz == null || frogFrame.xyz.Length != num * 3)
					{
						throw new InvalidDataException("Frame com quantidade incorreta de vertices:" + frogClip.name);
					}
					uv = frogFrame.xyz;
					foreach (float value2 in uv)
					{
						if (!Finite(value2) || Math.Abs(value2) > 5f)
						{
							throw new InvalidDataException("Vertice nao finito ou fora dos limites:" + frogClip.name);
						}
					}
				}
			}
		}
	}
	internal enum FrogPhase
	{
		Idle,
		Warning,
		Extend,
		Retract,
		Spit,
		Recovery,
		Dead
	}
	internal enum FrogAttack
	{
		Tongue,
		Venom
	}
	internal sealed class FrogBrain
	{
		internal const float Health = 360f;

		internal const float Detect = 24f;

		internal const float Leash = 8f;

		internal const float TongueRange = 12f;

		internal const float SpitRange = 18f;

		internal const float TongueDamage = 36f;

		internal const float TongueImpact = 28f;

		internal const float VenomDamage = 16f;

		internal const float VenomImpact = 8f;

		internal const float ExtensionTime = 0.22f;

		internal const float RetractionTime = 0.38f;

		internal const float SpitSpeed = 14f;

		private int completed;

		internal FrogPhase Phase { get; private set; }

		internal FrogAttack Attack { get; private set; }

		internal float Started { get; private set; }

		internal float Deadline { get; private set; }

		private void Begin(FrogPhase phase, float time, float length)
		{
			Phase = phase;
			Started = time;
			Deadline = time + length;
		}

		internal FrogPhase Step(float time, bool alive, bool visible, float distance)
		{
			if (!alive)
			{
				Begin(FrogPhase.Dead, time, 0f);
				return Phase;
			}
			if (Phase == FrogPhase.Dead)
			{
				return Phase;
			}
			if (Phase == FrogPhase.Warning && !visible)
			{
				Begin(FrogPhase.Recovery, time, 0.8f);
				return Phase;
			}
			switch (Phase)
			{
			case FrogPhase.Idle:
				if (visible && distance <= 18f)
				{
					Attack = ((!(distance <= 12f) || (completed % 3 == 2 && !(distance < 4f))) ? FrogAttack.Venom : FrogAttack.Tongue);
					Begin(FrogPhase.Warning, time, (Attack == FrogAttack.Tongue) ? 0.7f : 1f);
				}
				break;
			case FrogPhase.Warning:
				if (time >= Deadline)
				{
					Begin((Attack == FrogAttack.Tongue) ? FrogPhase.Extend : FrogPhase.Spit, time, (Attack == FrogAttack.Tongue) ? 0.22f : 0.18f);
				}
				break;
			case FrogPhase.Extend:
				if (time >= Deadline)
				{
					Begin(FrogPhase.Retract, time, 0.38f);
				}
				break;
			case FrogPhase.Retract:
			case FrogPhase.Spit:
				if (time >= Deadline)
				{
					completed++;
					Begin(FrogPhase.Recovery, time, (Attack == FrogAttack.Tongue) ? 1.25f : 2f);
				}
				break;
			case FrogPhase.Recovery:
				if (time >= Deadline)
				{
					Begin(FrogPhase.Idle, time, 0f);
				}
				break;
			}
			return Phase;
		}

		internal float Progress(float time)
		{
			return Math.Max(0f, Math.Min(1f, (time - Started) / Math.Max(0.001f, Deadline - Started)));
		}

		internal static float SegmentFraction(float px, float py, float pz, float ax, float ay, float az, float bx, float by, float bz)
		{
			float num = bx - ax;
			float num2 = by - ay;
			float num3 = bz - az;
			float num4 = num * num + num2 * num2 + num3 * num3;
			if (!(num4 < 1E-06f))
			{
				return Math.Max(0f, Math.Min(1f, ((px - ax) * num + (py - ay) * num2 + (pz - az) * num3) / num4));
			}
			return 0f;
		}
	}
	internal sealed class HiddenFrogReceiver : MonoBehaviour
	{
		private readonly List<Renderer> renderers = new List<Renderer>();

		private float next;

		private void LateUpdate()
		{
			if (Time.unscaledTime >= next)
			{
				((Component)this).GetComponentsInChildren<Renderer>(true, renderers);
				next = Time.unscaledTime + 0.15f;
			}
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = false;
				}
			}
		}
	}
	internal sealed class FrogEnemy : MonoBehaviour
	{
		private sealed class Shot
		{
			internal Vector3 Position;

			internal Vector3 Direction;

			internal float Travel;

			internal GameObject Visual;
		}

		private Character body;

		private FrogVisual visual;

		private CharacterController motor;

		private Vector3 home;

		private Vector3 aim;

		private Vector3 castStart;

		private Vector3 previousTip;

		private readonly FrogBrain brain = new FrogBrain();

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

		private readonly List<Collider> receivers = new List<Collider>();

		private List<Character> targets = new List<Character>();

		private readonly List<Shot> shots = new List<Shot>();

		private StatusEffect poison;

		private float clock;

		private float vertical;

		private float nextTargets;

		private float nextVisibility;

		private bool ready;

		private bool dead;

		internal void Initialize(Character native, FrogVisual model)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Expected O, but got Unknown
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Expected O, but got Unknown
			body = native;
			visual = model;
			home = ((Component)this).transform.position;
			CharacterAI component = ((Component)body).GetComponent<CharacterAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			NavMeshAgent component2 = ((Component)body).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			CharacterControl component3 = ((Component)body).GetComponent<CharacterControl>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			body.Animator.applyRootMotion = false;
			if ((Object)(object)body.CharacterController != (Object)null)
			{
				((Collider)body.CharacterController).enabled = false;
			}
			Collider[] componentsInChildren = ((Component)body).GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Rigidbody[] componentsInChildren2 = ((Component)body).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren2)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			motor = ((Component)this).gameObject.AddComponent<CharacterController>();
			motor.radius = 0.95f;
			motor.height = 2.65f;
			motor.center = Vector3.up * 1.325f;
			motor.skinWidth = 0.025f;
			motor.stepOffset = 0.25f;
			motor.slopeLimit = 50f;
			motor.minMoveDistance = 0f;
			int num = LayerMask.NameToLayer("Hitbox");
			if (num < 0)
			{
				throw new InvalidOperationException("Hitbox layer ausente");
			}
			List<Hitbox> list = new List<Hitbox>();
			for (int j = 0; j < 2; j++)
			{
				GameObject val = new GameObject("Sapo_Receptor_" + j);
				val.transform.SetParent(((Component)body).transform, false);
				val.layer = num;
				if (j == 0)
				{
					CapsuleCollider val2 = val.AddComponent<CapsuleCollider>();
					val2.center = Vector3.up * 1.12f;
					val2.radius = 0.95f;
					val2.height = 2.25f;
					((Collider)val2).isTrigger = true;
					receivers.Add((Collider)(object)val2);
				}
				else
				{
					SphereCollider val3 = val.AddComponent<SphereCollider>();
					val3.center = new Vector3(0f, 1.45f, 0.8f);
					val3.radius = 0.75f;
					((Collider)val3).isTrigger = true;
					receivers.Add((Collider)(object)val3);
				}
				Hitbox val4 = val.AddComponent<Hitbox>();
				val4.OwnerChar = body;
				val4.Melee = true;
				val4.Ranged = true;
				list.Add(val4);
			}
			FieldInfo? field = typeof(Character).GetField("m_hitboxes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("Character.m_hitboxes");
			}
			field.SetValue(body, list.ToArray());
			int num2 = LayerMask.NameToLayer("LockingPoints");
			if (num2 < 0 || (Global.LockingPointsMask & (1 << num2)) == 0)
			{
				throw new InvalidOperationException("LockingPoints layer ausente");
			}
			GameObject val5 = new GameObject("Sapo_Mira_TAB");
			val5.transform.SetParent(((Component)body).transform, false);
			val5.transform.localPosition = new Vector3(0f, 1.65f, 0.2f);
			val5.layer = num2;
			SphereCollider val6 = val5.AddComponent<SphereCollider>();
			val6.radius = 0.2f;
			((Collider)val6).isTrigger = true;
			receivers.Add((Collider)(object)val6);
			LockingPoint obj2 = val5.AddComponent<LockingPoint>();
			obj2.OwnerChar = body;
			obj2.HideFlare = false;
			poison = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Poisoned");
			if ((Object)(object)poison == (Object)null)
			{
				Plugin.Instance.Message("AVISO:Poisoned ausente;ataques causam dano mas sem veneno.");
			}
			Character obj3 = body;
			obj3.OnDeath = (UnityAction)Delegate.Combine((Delegate?)(object)obj3.OnDeath, (Delegate?)new UnityAction(Die));
			ready = true;
		}

		private static bool Valid(Character c)
		{
			if ((Object)(object)c != (Object)null && c.IsLocalPlayer)
			{
				return c.Alive;
			}
			return false;
		}

		private void Update()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_017a: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_01f4: 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_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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_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_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: 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_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: 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_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: 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_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			if (!ready || (Object)(object)body == (Object)null || (Object)(object)visual == (Object)null)
			{
				return;
			}
			if (!body.Alive)
			{
				Die();
			}
			if (Time.unscaledTime >= nextVisibility)
			{
				visual.Visible((Object)(object)Plugin.Nearest(((Component)this).transform.position, 150f) != (Object)null);
				nextVisibility = Time.unscaledTime + 0.25f;
			}
			if ((Object)(object)NetworkLevelLoader.Instance == (Object)null || !NetworkLevelLoader.Instance.IsOverallLoadingDone || NetworkLevelLoader.Instance.IsGameplayPaused)
			{
				return;
			}
			float dt = Mathf.Min(Time.deltaTime, 0.05f);
			clock += Time.deltaTime;
			if (dead)
			{
				visual.Pose(clock, 0f, FrogPhase.Dead, 0f, brain.Attack);
				return;
			}
			if (clock >= nextTargets)
			{
				targets.Clear();
				CharacterManager.Instance.FindCharactersInRange(((Component)this).transform.position, 26f, ref targets);
				nextTargets = clock + 0.1f;
			}
			Character val = null;
			float num = 24f;
			Vector3 val2;
			foreach (Character target in targets)
			{
				if (Valid(target))
				{
					val2 = target.CenterPosition - visual.Muzzle;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					if (magnitude < num)
					{
						val = target;
						num = magnitude;
					}
				}
			}
			int num3;
			if ((Object)(object)val != (Object)null && Mathf.Abs(((Component)val).transform.position.y - ((Component)this).transform.position.y) < 4f)
			{
				float num2 = Clip(visual.Muzzle, val.CenterPosition - visual.Muzzle, 0.14f);
				val2 = val.CenterPosition - visual.Muzzle;
				num3 = ((num2 >= ((Vector3)(ref val2)).magnitude - 0.03f) ? 1 : 0);
			}
			else
			{
				num3 = 0;
			}
			bool flag = (byte)num3 != 0;
			if ((Object)(object)val != (Object)null && brain.Phase == FrogPhase.Idle)
			{
				Turn(val.CenterPosition - ((Component)this).transform.position, dt);
			}
			if ((Object)(object)val != (Object)null && brain.Phase == FrogPhase.Idle)
			{
				Vector3 val3 = val.CenterPosition - ((Component)this).transform.position;
				val3.y = 0f;
				flag &= ((Vector3)(ref val3)).sqrMagnitude < 0.001f || Vector3.Angle(((Component)this).transform.forward, val3) < 20f;
			}
			FrogPhase phase = brain.Phase;
			if (phase == FrogPhase.Extend)
			{
				Extend(brain.Progress(clock));
			}
			FrogPhase frogPhase = brain.Step(clock, alive: true, flag, num);
			if (frogPhase != phase)
			{
				if (frogPhase == FrogPhase.Warning && (Object)(object)val != (Object)null)
				{
					aim = val.CenterPosition;
					hit.Clear();
				}
				if (frogPhase == FrogPhase.Extend || frogPhase == FrogPhase.Spit)
				{
					castStart = visual.Muzzle;
					Vector3 val4 = aim - castStart;
					if (((Vector3)(ref val4)).sqrMagnitude < 0.001f)
					{
						val4 = ((Component)this).transform.forward;
					}
					aim = ((Vector3)(ref val4)).normalized;
					previousTip = castStart;
					if (frogPhase == FrogPhase.Spit)
					{
						shots.Add(new Shot
						{
							Position = castStart,
							Direction = aim,
							Visual = visual.Seed(castStart)
						});
					}
				}
			}
			float num4 = brain.Progress(clock);
			float speed = Move(val, dt);
			visual.Pose(clock, speed, frogPhase, num4, brain.Attack);
			switch (frogPhase)
			{
			case FrogPhase.Extend:
				Extend(num4);
				break;
			case FrogPhase.Retract:
			{
				float num5 = Clip(castStart, aim * 12f, 0.14f);
				visual.Tongue(castStart, castStart + aim * num5 * (1f - num4), show: true);
				break;
			}
			default:
				visual.Tongue(Vector3.zero, Vector3.zero, show: false);
				break;
			}
			Projectiles(dt);
		}

		private void Turn(Vector3 direction, float dt)
		{
			//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_002c: 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)
			direction.y = 0f;
			if (((Vector3)(ref direction)).sqrMagnitude > 0.001f)
			{
				((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(direction), 200f * dt);
			}
		}

		private float Move(Character target, float dt)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_017e: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			if (brain.Phase == FrogPhase.Idle)
			{
				Vector3 val2 = (((Object)(object)target == (Object)null) ? home : ((Component)target).transform.position) - ((Component)this).transform.position;
				val2.y = 0f;
				Vector3 val3 = ((Component)this).transform.position - home;
				val3.y = 0f;
				bool flag = (Object)(object)target == (Object)null || ((Vector3)(ref val3)).magnitude > 7.75f;
				if (flag)
				{
					val2 = home - ((Component)this).transform.position;
					val2.y = 0f;
				}
				int num;
				if ((Object)(object)target != (Object)null)
				{
					Vector3 val4 = target.CenterPosition - visual.Muzzle;
					num = ((((Vector3)(ref val4)).magnitude > 10f) ? 1 : 0);
				}
				else
				{
					num = 0;
				}
				bool flag2 = (byte)num != 0;
				if (((Vector3)(ref val2)).magnitude > 0.2f && (flag || flag2))
				{
					Vector3 val5 = ((Vector3)(ref val2)).normalized;
					Vector3 start = ((Component)this).transform.position + Vector3.up * 1.4f;
					if (Clip(start, val5 * 1.65f, 0.85f) < 1.6f)
					{
						Vector3 val6 = Quaternion.Euler(0f, -65f, 0f) * val5;
						Vector3 val7 = Quaternion.Euler(0f, 65f, 0f) * val5;
						val5 = ((Clip(start, val6 * 1.65f, 0.85f) >= 1.6f) ? val6 : ((!(Clip(start, val7 * 1.65f, 0.85f) >= 1.6f)) ? Vector3.zero : val7));
					}
					Vector3 val8 = ((Component)this).transform.position + val5 * 1.8f * dt;
					Vector3 val9 = val8 - home;
					val9.y = 0f;
					if ((flag || ((Vector3)(ref val9)).magnitude <= 8f) && FrogGround.Surface(val8 + val5, out var floor, out var _) && Mathf.Abs(floor.y - ((Component)this).transform.position.y) < 0.6f)
					{
						val = val5 * 1.8f;
						Turn(val5, dt);
					}
				}
			}
			vertical = (motor.isGrounded ? (-2f) : Mathf.Max(vertical - 22f * dt, -20f));
			Vector3 position = ((Component)this).transform.position;
			motor.Move((val + Vector3.up * vertical) * dt);
			Vector3 val10 = ((Component)this).transform.position - position;
			val10.y = 0f;
			return ((Vector3)(ref val10)).magnitude / Mathf.Max(dt, 0.001f);
		}

		private void Extend(float progress)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			//IL_00b3: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0140: Unknown result type (might be due to invalid IL or missing references)
			float num = Clip(castStart, aim * 12f * progress, 0.14f);
			Vector3 val = castStart + aim * num;
			foreach (Character target in targets)
			{
				if (Valid(target) && !hit.Contains(target))
				{
					Vector3 centerPosition = target.CenterPosition;
					float num2 = FrogBrain.SegmentFraction(centerPosition.x, centerPosition.y, centerPosition.z, previousTip.x, previousTip.y, previousTip.z, val.x, val.y, val.z);
					Vector3 segment = centerPosition - castStart;
					Vector3 val2 = centerPosition - Vector3.Lerp(previousTip, val, num2);
					if (!(((Vector3)(ref val2)).sqrMagnitude > 0.42249995f) && !(Clip(castStart, segment, 0.14f) < ((Vector3)(ref segment)).magnitude - 0.03f))
					{
						hit.Add(target);
						bool flag = PhysicalContactHit.Apply((MonoBehaviour)(object)this, body, target, 36f, aim, 28f, blockable: true);
						PoisonOnHit.Apply(body, target, poison, flag);
						Plugin.Instance.Message("Lingua " + (flag ? "BLOQUEADA" : "ACERTO") + ";um acerto;Physical36/impact28.");
					}
				}
			}
			previousTip = val;
			visual.Tongue(castStart, val, show: true);
		}

		private void Projectiles(float dt)
		{
			//IL_003b: 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_0047: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			for (int num = shots.Count - 1; num >= 0; num--)
			{
				Shot shot = shots[num];
				float num2 = Mathf.Min(14f * dt, 18f - shot.Travel);
				float num3 = Clip(shot.Position, shot.Direction * num2, 0.12f);
				Vector3 val = shot.Position + shot.Direction * num3;
				Character val2 = null;
				float num4 = 2f;
				foreach (Character target in targets)
				{
					if (Valid(target))
					{
						Vector3 centerPosition = target.CenterPosition;
						float num5 = FrogBrain.SegmentFraction(centerPosition.x, centerPosition.y, centerPosition.z, shot.Position.x, shot.Position.y, shot.Position.z, val.x, val.y, val.z);
						Vector3 segment = centerPosition - shot.Position;
						Vector3 val3 = centerPosition - Vector3.Lerp(shot.Position, val, num5);
						if (((Vector3)(ref val3)).sqrMagnitude < 0.3025f && num5 < num4 && Clip(shot.Position, segment, 0.12f) >= ((Vector3)(ref segment)).magnitude - 0.02f)
						{
							val2 = target;
							num4 = num5;
						}
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.ReceiveHit((Object)null, new DamageList((Types)2, 16f), shot.Direction, val2.CenterPosition, 45f, 1f, body, 8f, true);
					PoisonOnHit.Apply(body, val2, poison, blocked: false);
				}
				shot.Travel += num3;
				shot.Position = val;
				if ((Object)(object)val2 != (Object)null || num3 < num2 - 0.001f || shot.Travel >= 17.999f)
				{
					if ((Object)(object)shot.Visual != (Object)null)
					{
						Object.Destroy((Object)(object)shot.Visual);
					}
					shots.RemoveAt(num);
				}
				else if ((Object)(object)shot.Visual != (Object)null)
				{
					shot.Visual.transform.position = val;
					shot.Visual.transform.rotation = Quaternion.LookRotation(shot.Direction);
				}
			}
		}

		private float Clip(Vector3 start, Vector3 segment, float radius)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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)
			float num = ((Vector3)(ref segment)).magnitude;
			if (num < 1E-05f)
			{
				return num;
			}
			RaycastHit[] array = Physics.SphereCastAll(start, radius, segment / num, num, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)this).transform) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>() != (Object)null))
				{
					num = Mathf.Min(num, ((RaycastHit)(ref val)).distance);
				}
			}
			return num;
		}

		private void Die()
		{
			if (dead)
			{
				return;
			}
			dead = true;
			brain.Step(clock, alive: false, visible: false, 0f);
			visual.Die();
			foreach (Collider receiver in receivers)
			{
				if ((Object)(object)receiver != (Object)null)
				{
					receiver.enabled = false;
				}
			}
			if ((Object)(object)motor != (Object)null)
			{
				((Collider)motor).enabled = false;
			}
			ClearShots();
			Plugin.Instance.Message("MORTO:ataques/mira cancelados,sem drop;F10 perto do lote recria SOMENTE o sapo.");
		}

		private void ClearShots()
		{
			foreach (Shot shot in shots)
			{
				if ((Object)(object)shot.Visual != (Object)null)
				{
					Object.Destroy((Object)(object)shot.Visual);
				}
			}
			shots.Clear();
		}

		private void LateUpdate()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (ready && (Object)(object)body != (Object)null)
			{
				((Component)body).transform.position = ((Component)this).transform.position;
				((Component)body).transform.rotation = ((Component)this).transform.rotation;
			}
		}

		private void OnDestroy()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)body != (Object)null)
			{
				Character obj = body;
				obj.OnDeath = (UnityAction)Delegate.Remove((Delegate?)(object)obj.OnDeath, (Delegate?)new UnityAction(Die));
			}
			ClearShots();
		}
	}
	internal static class FrogGround
	{
		internal static bool Surface(Vector3 world, out Vector3 floor, out Collider support)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00fa: 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_00d2: 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)
			floor = world;
			support = null;
			RaycastHit[] array = Physics.RaycastAll(new Ray(world + Vector3.up * 7f, Vector3.down), 17f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!((Object)(object)collider == (Object)null) && collider.enabled && !collider.isTrigger && !(((RaycastHit)(ref val)).normal.y < 0.7f) && !(Mathf.Abs(((RaycastHit)(ref val)).point.y - world.y) > 4f) && !((Object)collider).name.ToLowerInvariant().Contains("water") && ((Object)(object)support == (Object)null || Mathf.Abs(((RaycastHit)(ref val)).point.y - world.y) < Mathf.Abs(floor.y - world.y)))
				{
					floor = ((RaycastHit)(ref val)).point;
					support = collider;
				}
			}
			return (Object)(object)support != (Object)null;
		}
	}
	internal sealed class FrogLot
	{
		internal readonly int Number;

		internal readonly string UID;

		internal readonly string Sector;

		internal readonly Vector3 Position;

		internal static readonly FrogLot[] All = new FrogLot[4]
		{
			new FrogLot(1, -1540f, 255f, -130f),
			new FrogLot(2, -1400f, 255f, -149f),
			new FrogLot(3, -1480f, 255f, -219f),
			new FrogLot(4, -1494f, 255f, -39f)
		};

		internal FrogLot(int number, float x, float y, float z)
		{
			//IL_004e: 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)
			Number = number;
			UID = "codex.character.sapo.brejo.receiver" + ((number == 1) ? "" : ("." + number));
			Position = new Vector3(1783f + x, 255f, 1796.7f + z);
			Sector = "CierzoTutorial";
		}
	}
	internal sealed class FrogVisual : MonoBehaviour
	{
		private readonly List<Object> owned = new List<Object>();

		private Mesh skin;

		private Mesh tongueMesh;

		private Transform model;

		private Transform tongueTip;

		private Transform throat;

		private MeshRenderer tongueRenderer;

		private Material venom;

		private Vector3[][] idle;

		private Vector3[][] walk;

		private Vector3[] interpolated;

		private Vector3 mouth;

		private readonly TongueMesh tube = new TongueMesh();

		private float idleFps;

		private float walkFps;

		private float nextMesh;

		private float walkTime;

		private bool visible = true;

		private bool dead;

		private Renderer[] renderers;

		private static int[] sharedTriangles;

		private static Vector2[] sharedUv;

		private static Vector3[][] sharedIdle;

		private static Vector3[][] sharedWalk;

		private static Vector3 sharedMouth;

		private static float sharedIdleFps;

		private static float sharedWalkFps;

		internal Vector3 Muzzle => model.TransformPoint(mouth);

		private static bool Finite(float x)
		{
			if (!float.IsNaN(x))
			{
				return !float.IsInfinity(x);
			}
			return false;
		}

		internal static void ClearShared()
		{
			sharedTriangles = null;
			sharedUv = null;
			sharedIdle = null;
			sharedWalk = null;
		}

		private static void EnsureShared(string folder)
		{
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			if (sharedTriangles != null)
			{
				return;
			}
			FrogAsset frogAsset = FrogAssetReader.Read(Path.Combine(folder, "frog_mesh.json"));
			int num = frogAsset.uv.Length / 2;
			Vector3[][] array = null;
			Vector3[][] array2 = null;
			float num2 = 0f;
			float num3 = 0f;
			FrogClip[] clips = frogAsset.clips;
			foreach (FrogClip frogClip in clips)
			{
				if (frogClip.frames == null || frogClip.frames.Length < 2 || frogClip.frames.Length > 60 || !Finite(frogClip.fps) || frogClip.fps < 1f || frogClip.fps > 30f)
				{
					throw new InvalidDataException("Clip invalido");
				}
				Vector3[][] array3 = new Vector3[frogClip.frames.Length][];
				for (int j = 0; j < array3.Length; j++)
				{
					float[] xyz = frogClip.frames[j].xyz;
					if (xyz == null || xyz.Length != num * 3)
					{
						throw new InvalidDataException("Frame invalido");
					}
					array3[j] = (Vector3[])(object)new Vector3[num];
					for (int k = 0; k < num; k++)
					{
						float num4 = xyz[k * 3];
						float num5 = xyz[k * 3 + 1];
						float num6 = xyz[k * 3 + 2];
						if (!Finite(num4) || !Finite(num5) || !Finite(num6) || Mathf.Abs(num4) > 5f || Mathf.Abs(num5) > 5f || Mathf.Abs(num6) > 5f)
						{
							throw new InvalidDataException("Vertice fora do limite");
						}
						array3[j][k] = new Vector3(num4, num5, num6);
					}
				}
				if (frogClip.name == "idle" && array == null)
				{
					array = array3;
					num2 = frogClip.fps;
					continue;
				}
				if (frogClip.name == "walk" && array2 == null)
				{
					array2 = array3;
					num3 = frogClip.fps;
					continue;
				}
				throw new InvalidDataException("Clip desconhecido ou duplicado");
			}
			if (array == null || array2 == null)
			{
				throw new InvalidDataException("Idle/walk ausentes");
			}
			Vector2[] array4 = (Vector2[])(object)new Vector2[num];
			for (int l = 0; l < num; l++)
			{
				array4[l] = new Vector2(frogAsset.uv[2 * l], frogAsset.uv[2 * l + 1]);
			}
			sharedIdle = array;
			sharedWalk = array2;
			sharedIdleFps = num2;
			sharedWalkFps = num3;
			sharedUv = array4;
			sharedMouth = new Vector3(frogAsset.mouth[0], frogAsset.mouth[1], frogAsset.mouth[2]);
			sharedTriangles = frogAsset.triangles;
			Plugin.Instance.Message("ASSET LIDO:DataContractJson;vertices=" + num + ";triangulos=" + frogAsset.triangles.Length / 3 + ";clips=" + frogAsset.clips.Length + ";idle/walk24frames.");
		}

		internal void Build()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "Assets");
			EnsureShared(text);
			idle = sharedIdle;
			walk = sharedWalk;
			idleFps = sharedIdleFps;
			walkFps = sharedWalkFps;
			mouth = sharedMouth;
			int num = sharedUv.Length;
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			owned.Add((Object)(object)val);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(text, "frog_source.png"))) || ((Texture)val).width > 1024 || ((Texture)val).height > 1024)
			{
				throw new InvalidDataException("Textura ausente ou maior que1K");
			}
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Material val2 = Material(new Color(0.72f, 0.88f, 0.65f), 0.17f);
			val2.mainTexture = (Texture)(object)val;
			skin = new Mesh
			{
				name = "SapoCC0_2592tris_AnimacaoBaked"
			};
			owned.Add((Object)(object)skin);
			skin.MarkDynamic();
			skin.vertices = idle[0];
			skin.triangles = sharedTriangles;
			skin.uv = sharedUv;
			skin.RecalculateNormals();
			skin.RecalculateBounds();
			model = Piece("Sapo_Modelo_Externo", skin, val2).transform;
			interpolated = (Vector3[])(object)new Vector3[num];
			Material material = Material(new Color(0.57f, 0.13f, 0.25f), 0.48f);
			tongueMesh = new Mesh
			{
				name = "Lingua_Tubular_Fechada"
			};
			owned.Add((Object)(object)tongueMesh);
			tongueMesh.MarkDynamic();
			tongueRenderer = Piece("Sapo_Lingua", tongueMesh, material).GetComponent<MeshRenderer>();
			((Renderer)tongueRenderer).enabled = false;
			tongueTip = Sphere("Sapo_Ponta_Lingua", material, Vector3.one * 0.27f);
			((Component)tongueTip).gameObject.SetActive(false);
			throat = Sphere("Sapo_Garganta", Material(new Color(0.08f, 0.035f, 0.045f), 0.25f), new Vector3(0.35f, 0.24f, 0.15f));
			throat.SetParent(model, false);
			throat.localPosition = mouth - new Vector3(0f, 0.04f, 0.07f);
			((Component)throat).gameObject.SetActive(false);
			venom = Material(new Color(0.22f, 0.73f, 0.07f), 0.55f);
			venom.EnableKeyword("_EMISSION");
			venom.SetColor("_EmissionColor", new Color(0.07f, 0.24f, 0.005f));
			renderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
		}

		private Material Material(Color color, float gloss)
		{
			//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)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			Shader obj = Shader.Find("Standard") ?? Shader.Find("Diffuse");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("Shaders Standard/Diffuse ausentes");
			}
			Material val = new Material(obj)
			{
				color = color
			};
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", gloss);
			}
			owned.Add((Object)(object)val);
			return val;
		}

		private GameObject Piece(string name, Mesh mesh, Material material)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_003f: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return val;
		}

		private Transform Sphere(string name, Material material, Vector3 scale)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj).name = name;
			obj.transform.SetParent(((Component)this).transform, false);
			Collider component = obj.GetComponent<Collider>();
			component.enabled = false;
			Object.Destroy((Object)(object)component);
			obj.transform.localScale = scale;
			MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
			((Renderer)component2).sharedMaterial = material;
			((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component2).receiveShadows = false;
			return obj.transform;
		}

		internal GameObject Seed(Vector3 position)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = Sphere("Sapo_Cuspe_Venenoso", venom, new Vector3(0.25f, 0.25f, 0.4f));
			obj.SetParent((Transform)null, true);
			obj.position = position;
			return ((Component)obj).gameObject;
		}

		internal void Pose(float clock, float speed, FrogPhase phase, float progress, FrogAttack attack)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)model == (Object)null)
			{
				return;
			}
			if (dead)
			{
				model.localRotation = Quaternion.Euler(0f, 0f, 55f);
				model.localPosition = Vector3.up * 0.08f;
				return;
			}
			bool flag = speed > 0.1f && phase == FrogPhase.Idle;
			if (flag)
			{
				walkTime += Time.deltaTime * Mathf.Clamp(speed / 1.8f, 0f, 1.4f);
			}
			if (clock >= nextMesh && visible)
			{
				Vector3[][] array = (flag ? walk : idle);
				float num = (flag ? (walkTime * walkFps) : (clock * idleFps)) % (float)array.Length;
				int num2 = (int)num;
				int num3 = (num2 + 1) % array.Length;
				float num4 = num - (float)num2;
				for (int i = 0; i < interpolated.Length; i++)
				{
					interpolated[i] = Vector3.Lerp(array[num2][i], array[num3][i], num4);
				}
				skin.vertices = interpolated;
				skin.RecalculateNormals();
				skin.RecalculateBounds();
				nextMesh = clock + 1f / 24f;
			}
			float num5 = ((phase == FrogPhase.Warning) ? Mathf.Sin(progress * (float)Math.PI * 0.5f) : 0f);
			model.localRotation = Quaternion.Euler(-5f * num5, 0f, 0f);
			model.localPosition = Vector3.back * (0.09f * num5);
			bool active = phase == FrogPhase.Warning || phase == FrogPhase.Extend || phase == FrogPhase.Retract || phase == FrogPhase.Spit;
			((Component)throat).gameObject.SetActive(active);
			throat.localScale = new Vector3(0.35f, 0.24f + 0.12f * num5, 0.15f);
		}

		internal void Tongue(Vector3 start, Vector3 end, bool show)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			bool flag = show && !dead;
			((Renderer)tongueRenderer).enabled = flag && visible;
			((Component)tongueTip).gameObject.SetActive(flag);
			if (flag)
			{
				start = ((Component)this).transform.InverseTransformPoint(start);
				end = ((Component)this).transform.InverseTransformPoint(end);
				tube.Update(start, end);
				tongueMesh.vertices = tube.Vertices;
				tongueMesh.triangles = tube.Triangles;
				tongueMesh.RecalculateNormals();
				tongueMesh.RecalculateBounds();
				tongueTip.localPosition = end;
			}
		}

		internal void Visible(bool value)
		{
			visible = value;
			if (renderers != null)
			{
				Renderer[] array = renderers;
				foreach (Renderer val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.enabled = value;
					}
				}
			}
			if ((Object)(object)tongueRenderer != (Object)null)
			{
				((Renderer)tongueRenderer).enabled = value && ((Component)tongueTip).gameObject.activeSelf;
			}
		}

		internal void Die()
		{
			//IL_0008: 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)
			dead = true;
			Tongue(Vector3.zero, Vector3.zero, show: false);
			if ((Object)(object)throat != (Object)null)
			{
				((Component)throat).gameObject.SetActive(false);
			}
		}

		private void OnDestroy()
		{
			foreach (Object item in owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			owned.Clear();
		}
	}
	[BepInPlugin("codex.outward.sapo.brejo", "Codex - Sapo do Brejo Externo", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Slot
		{
			internal readonly FrogLot Lot;

			internal SL_Character Template;

			internal Character Body;

			internal GameObject Actor;

			internal bool Creating;

			internal bool Visited;

			internal int Generation;

			internal float Retry;

			internal float Warning;

			internal Slot(FrogLot lot)
			{
				Lot = lot;
			}
		}

		public const string Guid = "codex.outward.sapo.brejo";

		internal static Plugin Instance;

		internal static readonly Vector3 Position = FrogLot.All[0].Position;

		private readonly Slot[] slots = Array.ConvertAll(FrogLot.All, (FrogLot lot) => new Slot(lot));

		private float nextScan;

		private ConfigEntry<KeyboardShortcut> reset;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			reset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Teste", "Recriar", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Ate15m de um lote,F10 recria SOMENTE o sapo mais proximo.");
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += Loaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			Message("1.2.0:QUATRO sapos externos em " + FrogLot.All[0].Sector + ";360HP/lingua12m bloqueavel/cuspe18m/Poisoned100%;sem drop.");
		}

		private void Prepare()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00f1: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			Slot[] array = slots;
			foreach (Slot slot in array)
			{
				if (slot.Template == null)
				{
					slot.Template = new SL_Character
					{
						UID = slot.Lot.UID,
						Name = "Sapo dos Esporos",
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						DestroyOnDeath = false,
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						Faction = (Factions)9,
						CharacterVisualsData = new VisualData(),
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = -1,
						Boots_ID = -1,
						Backpack_ID = -1,
						Health = 360f,
						HealthRegen = 0f,
						Protection = 0f,
						Barrier = 0f,
						ImpactResist = 100f,
						Damage_Resists = new float[9],
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false
					};
					((ContentTemplate)slot.Template).ApplyTemplate();
				}
			}
			Message("Quatro receptores temporarios preparados;modelo/animacao CC0,sem reativar arquivos antigos.");
		}

		private void Loaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				((MonoBehaviour)this).StopAllCoroutines();
				Slot[] array = slots;
				foreach (Slot slot in array)
				{
					Cleanup(slot);
					slot.Visited = false;
					slot.Retry = 0f;
				}
				FrogVisual.ClearShared();
			}
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != FrogLot.All[0].Sector || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = reset.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				ResetNearest();
			}
			if (Time.realtimeSinceStartup < nextScan)
			{
				return;
			}
			nextScan = Time.realtimeSinceStartup + 0.25f;
			Slot[] array = slots;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Creating)
				{
					return;
				}
			}
			array = slots;
			foreach (Slot slot in array)
			{
				if (slot.Template == null || slot.Visited || Time.realtimeSinceStartup < slot.Retry || (Object)(object)Nearest(slot.Lot.Position, 130f) == (Object)null)
				{
					continue;
				}
				if (!FrogGround.Surface(slot.Lot.Position, out var floor, out var support))
				{
					Wait(slot, "Aguardando colliderreal " + slot.Lot.Sector);
					continue;
				}
				if (Physics.GetIgnoreLayerCollision(0, ((Component)support).gameObject.layer))
				{
					Wait(slot, "Default nao colide com camada do piso;nenhuma matriz global alterada");
					continue;
				}
				bool flag = false;
				Collider[] array2 = Physics.OverlapCapsule(floor + Vector3.up * 1.05f, floor + Vector3.up * 1.75f, 0.95f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				foreach (Collider val in array2)
				{
					if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)support)
					{
						Wait(slot, "Lote ocupado por " + ((Object)val).name + ";nao removido/deslocado");
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					((MonoBehaviour)this).StartCoroutine(Create(slot, floor, slot.Generation));
					break;
				}
			}
		}

		private void ResetNearest()
		{
			//IL_001f: 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)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Slot slot = null;
			float num = 225f;
			Slot[] array = slots;
			foreach (Slot slot2 in array)
			{
				Character val = Nearest(slot2.Lot.Position, 15f);
				if (!((Object)(object)val == (Object)null) && (!((Object)(object)val.CharacterUI != (Object)null) || !val.CharacterUI.IsMenuFocused))
				{
					Vector3 val2 = val.CenterPosition - slot2.Lot.Position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						slot = slot2;
					}
				}
			}
			if (slot != null)
			{
				Cleanup(slot);
				slot.Visited = false;
				slot.Retry = 0f;
				int i = slot.Lot.Number;
				Message("F10:recriando somente SAPO " + i);
			}
		}

		private void Wait(Slot slot, string why)
		{
			if (Time.realtimeSinceStartup >= slot.Warning)
			{
				int number = slot.Lot.Number;
				Message("SAPO " + number + ":" + why);
				slot.Warning = Time.realtimeSinceStartup + 15f;
			}
			slot.Retry = Time.realtimeSinceStartup + 2f;
		}

		private unsafe IEnumerator Create(Slot slot, Vector3 floor, int token)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			slot.Creating = true;
			try
			{
				slot.Body = slot.Template.Spawn(floor + Vector3.up * 0.04f, (string)null, (string)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			if ((Object)(object)slot.Body == (Object)null)
			{
				slot.Creating = false;
				slot.Retry = Time.realtimeSinceStartup + 5f;
				yield break;
			}
			((Component)slot.Body).gameObject.AddComponent<HiddenFrogReceiver>();
			float deadline = Time.realtimeSinceStartup + 25f;
			while (token == slot.Generation && (Object)(object)slot.Body != (Object)null && ((Object)(object)slot.Body.Stats == (Object)null || (Object)(object)slot.Body.Animator == (Object)null || slot.Body.Hitboxes == null || slot.Body.Hitboxes.Length == 0) && Time.realtimeSinceStartup < deadline)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (token != slot.Generation)
			{
				yield break;
			}
			if ((Object)(object)slot.Body == (Object)null)
			{
				slot.Creating = false;
				slot.Retry = Time.realtimeSinceStartup + 5f;
				yield break;
			}
			try
			{
				Character body = slot.Body;
				if ((Object)(object)body.Stats == (Object)null || (Object)(object)body.Animator == (Object)null || body.Hitboxes == null || body.Hitboxes.Length == 0)
				{
					throw new InvalidOperationException("Receptor incompleto");
				}
				body.Teleport(floor + Vector3.up * 0.04f, Quaternion.identity);
				body.Invincible = false;
				body.QuestInvicibility = false;
				body.QuestNonTargetable = false;
				body.Stats.SetHealth(360f);
				int number = slot.Lot.Number;
				slot.Actor = new GameObject("Codex_Sapo_Brejo_Externo_" + number);
				slot.Actor.transform.position = floor + Vector3.up * 0.04f;
				FrogVisual frogVisual = slot.Actor.AddComponent<FrogVisual>();
				frogVisual.Build();
				slot.Actor.AddComponent<FrogEnemy>().Initialize(body, frogVisual);
				slot.Visited = true;
				Plugin plugin = this;
				string[] obj = new string[9] { "SAPO ", null, null, null, null, null, null, null, null };
				number = slot.Lot.Number;
				obj[1] = number.ToString();
				obj[2] = " PRONTO: ";
				Vector3 val = floor;
				obj[3] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				obj[4] = ";UID=";
				obj[5] = slot.Lot.UID;
				obj[6] = ";apoio=";
				obj[7] = slot.Lot.Sector;
				obj[8] = ";360HP/lingua12m/miraTAB/cuspe18m;semNavMesh.";
				plugin.Message(string.Concat(obj));
			}
			catch (Exception ex2)
			{
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				int number = slot.Lot.Number;
				logger.LogError((object)("[SapoBrejo] Setup SAPO " + number + ":" + ex2));
				Cleanup(slot);
				slot.Retry = Time.realtimeSinceStartup + 5f;
			}
			slot.Creating = false;
		}

		internal static Character Nearest(Vector3 at, float radius)
		{
			//IL_0059: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			CharacterManager instance = CharacterManager.Instance;
			if (((instance != null) ? instance.Characters : null) == null)
			{
				return null;
			}
			Character result = null;
			float num = radius * radius;
			foreach (Character value in CharacterManager.Instance.Characters.Values)
			{
				if (!((Object)(object)value == (Object)null) && value.IsLocalPlayer && value.Alive && !(Mathf.Abs(((Component)value).transform.position.y - at.y) > 12f))
				{
					Vector3 val = value.CenterPosition - at;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = value;
					}
				}
			}
			return result;
		}

		internal void Message(string text)
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[SapoBrejo] " + text));
		}

		private void Cleanup(Slot slot)
		{
			slot.Generation++;
			if ((Object)(object)slot.Actor != (Object)null)
			{
				Object.Destroy((Object)(object)slot.Actor);
			}
			if ((Object)(object)slot.Body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(slot.Body);
			}
			slot.Actor = null;
			slot.Body = null;
			slot.Creating = false;
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= Loaded;
			((MonoBehaviour)this).StopAllCoroutines();
			Slot[] array = slots;
			foreach (Slot slot in array)
			{
				Cleanup(slot);
				if (slot.Template != null)
				{
					slot.Template.Unregister();
				}
			}
			FrogVisual.ClearShared();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	internal sealed class TongueMesh
	{
		private const int Sides = 12;

		private const int Rings = 5;

		internal readonly Vector3[] Vertices = (Vector3[])(object)new Vector3[62];

		internal readonly int[] Triangles = new int[360];

		internal TongueMesh()
		{
			int num = 0;
			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					int num2 = i * 12 + j;
					int num3 = i * 12 + (j + 1) % 12;
					int num4 = num2 + 12;
					int num5 = num3 + 12;
					Triangles[num++] = num2;
					Triangles[num++] = num4;
					Triangles[num++] = num3;
					Triangles[num++] = num3;
					Triangles[num++] = num4;
					Triangles[num++] = num5;
				}
			}
			int num6 = 60;
			int num7 = num6 + 1;
			for (int k = 0; k < 12; k++)
			{
				int num8 = (k + 1) % 12;
				Triangles[num++] = num6;
				Triangles[num++] = k;
				Triangles[num++] = num8;
				Triangles[num++] = num7;
				Triangles[num++] = 48 + num8;
				Triangles[num++] = 48 + k;
			}
		}

		internal void Update(Vector3 start, Vector3 end)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = end - start;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				val = Vector3.forward;
			}
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = Vector3.Cross(normalized, (Mathf.Abs(normalized.y) > 0.9f) ? Vector3.forward : Vector3.up);
			Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
			val2 = Vector3.Cross(normalized2, normalized);
			Vector3 normalized3 = ((Vector3)(ref val2)).normalized;
			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					float num = (float)i / 4f;
					float num2 = (float)j * (float)Math.PI * 2f / 12f;
					float num3 = Mathf.Lerp(0.145f, 0.06f, num);
					Vertices[i * 12 + j] = Vector3.Lerp(start, end, num) + (normalized2 * Mathf.Cos(num2) + normalized3 * Mathf.Sin(num2)) * num3;
				}
			}
			Vertices[60] = start;
			Vertices[61] = end;
		}
	}
}

BepInEx/plugins/Codex_Treinador_Habilidades/CodexTreinadorHabilidades.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexTreinadorHabilidades
{
	[BepInPlugin("codex.outward.treinador.habilidades", "Codex - Treinadora das Muralhas", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.treinador.habilidades";

		private const string Uid = "codex.character.cidade.treinador.habilidades";

		private static readonly Vector3[] Spots = (Vector3[])(object)new Vector3[3]
		{
			new Vector3(1751f, 255f, 1818.7f),
			new Vector3(1748f, 255f, 1816.7f),
			new Vector3(1746f, 255f, 1819.7f)
		};

		private const string SceneName = "CierzoTutorial";

		private SL_Character template;

		private Character body;

		private float nextScan;

		private float nextRetry;

		private int generation;

		private bool spawning;

		private List<Character> nearbyPlayers = new List<Character>();

		internal static Plugin Instance;

		private void Awake()
		{
			Instance = this;
			SL.OnPacksLoaded += Prepare;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			SceneManager.sceneLoaded += Loaded;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"[Treinador] Iria em CierzoTutorial;8 habilidades por dialogo;sem aprendizagem automatica;sem custo.");
		}

		private void Prepare()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_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_0036: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0101: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			if (template == null)
			{
				SL_Character val = new SL_Character
				{
					UID = "codex.character.cidade.treinador.habilidades",
					Name = "Iria, Mestra de Armas",
					SaveType = (CharSaveType)0,
					SceneToSpawn = "",
					StartingPose = (SpellCastType)(-1),
					Scale = Vector3.one,
					StartSheathed = true,
					DestroyOnDeath = false,
					Faction = (Factions)0,
					Health = 500f,
					HealthRegen = 0f,
					Weapon_ID = -1,
					Shield_ID = -1,
					Helmet_ID = -1,
					Chest_ID = 3100080,
					Boots_ID = 3100082,
					Backpack_ID = -1,
					CharacterVisualsData = new VisualData
					{
						Gender = (Gender)1,
						SkinIndex = 2,
						HeadVariationIndex = 3,
						HairStyleIndex = 8,
						HairColorIndex = 6
					},
					LootableOnDeath = false,
					DropWeapons = false,
					DropPouchContents = false,
					AutoTeleportWhenFar = false
				};
				((ContentTemplate)val).ApplyTemplate();
				template = val;
			}
		}

		private void Loaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
			}
		}

		private void Update()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextScan)
			{
				return;
			}
			nextScan = Time.unscaledTime + 1f;
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if (spawning || (Object)(object)body != (Object)null || template == null || Time.unscaledTime < nextRetry || PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "CierzoTutorial" || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)CharacterManager.Instance == (Object)null)
			{
				return;
			}
			nearbyPlayers.Clear();
			CharacterManager.Instance.FindCharactersInRange(Spots[0], 140f, ref nearbyPlayers);
			bool flag = false;
			foreach (Character nearbyPlayer in nearbyPlayers)
			{
				if ((Object)(object)nearbyPlayer != (Object)null && nearbyPlayer.IsLocalPlayer && nearbyPlayer.Alive && Mathf.Abs(((Component)nearbyPlayer).transform.position.y - Spots[0].y) < 12f)
				{
					Vector3 val = ((Component)nearbyPlayer).transform.position - Spots[0];
					if (((Vector3)(ref val)).sqrMagnitude < 19600f)
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				return;
			}
			Vector3[] spots = Spots;
			for (int i = 0; i < spots.Length; i++)
			{
				if (Surface(spots[i], out var floor, out var support) && Clear(floor, support))
				{
					((MonoBehaviour)this).StartCoroutine(Create(floor, generation));
					return;
				}
			}
			nextRetry = Time.unscaledTime + 5f;
		}

		private static bool Surface(Vector3 guess, out Vector3 floor, out Collider support)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			floor = guess;
			support = null;
			RaycastHit[] array = Physics.RaycastAll(new Ray(guess + Vector3.up * 7f, Vector3.down), 17f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!((Object)(object)collider == (Object)null) && collider.enabled && !collider.isTrigger && !(((RaycastHit)(ref val)).normal.y < 0.8f) && !(Mathf.Abs(((RaycastHit)(ref val)).point.y - guess.y) > 3f) && ((Object)collider).name.IndexOf("water", StringComparison.OrdinalIgnoreCase) < 0 && ((Object)collider).name.IndexOf("agua", StringComparison.OrdinalIgnoreCase) < 0 && ((Object)(object)support == (Object)null || Mathf.Abs(((RaycastHit)(ref val)).point.y - guess.y) < Mathf.Abs(floor.y - guess.y)))
				{
					floor = ((RaycastHit)(ref val)).point;
					support = collider;
				}
			}
			return (Object)(object)support != (Object)null;
		}

		private static bool Clear(Vector3 at, Collider floor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapCapsule(at + Vector3.up * 0.75f, at + Vector3.up * 1.7f, 0.55f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)floor)
				{
					return false;
				}
			}
			return true;
		}

		private unsafe IEnumerator Create(Vector3 floor, int token)
		{
			//IL_000e: 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)
			spawning = true;
			Character spawned = null;
			try
			{
				spawned = (body = template.Spawn(floor + Vector3.up * 0.12f, (string)null, (string)null));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[Treinador] SPAWN:" + ex));
			}
			float deadline = Time.unscaledTime + 25f;
			while ((Object)(object)spawned != (Object)null && token == generation && (!spawned.Initialized || (Object)(object)spawned.Animator == (Object)null || (Object)(object)((Component)spawned).GetComponentInChildren<CharacterVisuals>(true) == (Object)null) && Time.unscaledTime < deadline)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (token != generation)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)spawned == (Object)null || !spawned.Initialized || (Object)(object)spawned.Animator == (Object)null || (Object)(object)((Component)spawned).GetComponentInChildren<CharacterVisuals>(true) == (Object)null)
				{
					throw new InvalidOperationException("corpo ainda incompleto");
				}
				if (!Surface(floor, out var floor2, out var support) || !Clear(floor2, support))
				{
					throw new InvalidOperationException("piso ou lote indisponivel");
				}
				spawned.Teleport(floor2 + Vector3.up * 0.12f, Quaternion.Euler(0f, 135f, 0f));
				spawned.Invincible = true;
				CharacterVisuals componentInChildren = ((Component)spawned).GetComponentInChildren<CharacterVisuals>(true);
				if ((Object)(object)((Component)componentInChildren).transform != (Object)(object)((Component)spawned).transform)
				{
					Transform transform = ((Component)componentInChildren).transform;
					transform.localPosition += Vector3.up * 0.08f;
				}
				TrainerDialogue.Attach(spawned);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				Vector3 val = floor2;
				logger.LogMessage((object)("[Treinador] NPC PRONTO uid=codex.character.cidade.treinador.habilidades;pos=" + ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString() + ";dialogo=8 habilidades"));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[Treinador] NPC WAIT:" + ex2));
				if ((Object)(object)spawned != (Object)null)
				{
					CustomCharacters.DestroyCharacterRPC(spawned);
				}
				body = null;
				nextRetry = Time.unscaledTime + 10f;
			}
			spawning = false;
		}

		private void Cleanup()
		{
			generation++;
			((MonoBehaviour)this).StopAllCoroutines();
			spawning = false;
			if ((Object)(object)body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(body);
			}
			body = null;
			nextRetry = (nextScan = 0f);
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= Loaded;
			Cleanup();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		internal void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)("[Treinador] " + message));
		}
	}
	internal static class TrainerDialogue
	{
		internal static void Attach(Character body)
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			GameObject obj = Resources.Load<GameObject>("editor/templates/TrainerTemplate");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("TrainerTemplate ausente");
			}
			GameObject val = Object.Instantiate<GameObject>(obj);
			((Object)val).name = "TreinadorHabilidades_Dialogo";
			val.transform.SetParent(((Component)body).transform, false);
			try
			{
				DialogueTreeController componentInChildren = val.GetComponentInChildren<DialogueTreeController>(true);
				DialogueActor componentInChildren2 = val.GetComponentInChildren<DialogueActor>(true);
				Graph val2 = (((Object)(object)componentInChildren == (Object)null) ? null : ((GraphOwner)componentInChildren).graph);
				Graph obj2 = ((val2 is DialogueTree) ? val2 : null);
				if (!(val2 is DialogueTreeExt) || (Object)(object)componentInChildren2 == (Object)null)
				{
					throw new InvalidOperationException("dialogo nativo incompleto");
				}
				if (!(At.GetField<DialogueTree>((DialogueTree)(object)obj2, "_actorParameters") is List<ActorParameter> { Count: not 0 } list))
				{
					throw new InvalidOperationException("ator nativo ausente");
				}
				componentInChildren2.SetName(body.Name);
				list[0].actor = (IDialogueActor)(object)componentInChildren2;
				list[0].name = body.Name;
				val2.allNodes.Clear();
				StatementNodeExt val3 = Line(val2, body.Name, "Lider, posso ensinar os golpes e rituais que reunimos em nossas jornadas. Qual deles voce quer praticar?");
				MultipleChoiceNodeExt val4 = val2.AddNode<MultipleChoiceNodeExt>();
				val2.primeNode = (Node)(object)val3;
				val2.ConnectNodes((Node)(object)val3, (Node)(object)val4, -1, -1);
				MultipleChoiceNodeExt val5 = val2.AddNode<MultipleChoiceNodeExt>();
				MultipleChoiceNodeExt val6 = val2.AddNode<MultipleChoiceNodeExt>();
				val4.availableChoices.Add(new Choice(new Statement("Tecnicas de combate.")));
				val4.availableChoices.Add(new Choice(new Statement("Rituais e magia.")));
				val4.availableChoices.Add(new Choice(new Statement("Volto depois.")));
				val2.ConnectNodes((Node)(object)val4, (Node)(object)val5, 0, -1);
				val2.ConnectNodes((Node)(object)val4, (Node)(object)val6, 1, -1);
				val2.ConnectNodes((Node)(object)val4, (Node)(object)Line(val2, body.Name, "Estarei aqui quando precisar treinar."), 2, -1);
				BuildChoices(val2, body.Name, val5, new int[4] { 0, 1, 2, 5 }, val4);
				BuildChoices(val2, body.Name, val6, new int[4] { 3, 4, 6, 7 }, val4);
				val.SetActive(true);
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		private static void BuildChoices(Graph graph, string speaker, MultipleChoiceNodeExt submenu, int[] indices, MultipleChoiceNodeExt main)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			for (int i = 0; i < indices.Length; i++)
			{
				int num = indices[i];
				submenu.availableChoices.Add(new Choice(new Statement(TrainerService.Names[num])));
				TrainerNode trainerNode = graph.AddNode<TrainerNode>();
				trainerNode.SkillIndex = num;
				StatementNodeExt val = (trainerNode.Output = Line(graph, speaker, ""));
				graph.ConnectNodes((Node)(object)submenu, (Node)(object)trainerNode, i, -1);
				graph.ConnectNodes((Node)(object)trainerNode, (Node)(object)val, -1, -1);
				graph.ConnectNodes((Node)(object)val, (Node)(object)submenu, -1, -1);
			}
			submenu.availableChoices.Add(new Choice(new Statement("Voltar.")));
			graph.ConnectNodes((Node)(object)submenu, (Node)(object)main, indices.Length, -1);
		}

		private static StatementNodeExt Line(Graph graph, string speaker, string text)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			StatementNodeExt obj = graph.AddNode<StatementNodeExt>();
			obj.SetActorName(speaker);
			obj.statement = new Statement(text);
			obj.ContinueOnStatementFinished = true;
			return obj;
		}
	}
	public sealed class TrainerNode : DTNode
	{
		public int SkillIndex;

		public StatementNodeExt Output;

		public override bool requireActorSelection => false;

		protected override Status OnExecute(Component agent, IBlackboard bb)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			if (Output != null && SkillIndex >= 0 && SkillIndex < TrainerService.Ids.Length)
			{
				DialogueTree dLGTree = ((DTNode)this).DLGTree;
				DialogueTreeExt val = (DialogueTreeExt)(object)((dLGTree is DialogueTreeExt) ? dLGTree : null);
				Output.statement = new Statement(TrainerService.Learn(((Object)(object)val == (Object)null) ? null : val.Instigator, SkillIndex));
				((DTNode)this).DLGTree.Continue(0);
				return (Status)1;
			}
			return (Status)4;
		}
	}
	internal static class TrainerService
	{
		internal static readonly int[] Ids = new int[8] { 9106910, 9106920, 9106930, 9106950, 9106960, 9106970, 9106980, 9106990 };

		internal static readonly string[] Names = new string[8] { "Combo Rubro", "Resvaldo Lunar", "Salto da Tempestade", "Lanca da Tempestade", "Uivo da Loucura", "Marca do Carrasco", "Prisao de Gelo", "Ritual das Cinzas" };

		internal static string Learn(Character player, int index)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)player == (Object)null) && player.IsLocalPlayer && player.IsPhotonPlayerLocal && player.Alive && player.Initialized)
			{
				CharacterInventory inventory = player.Inventory;
				if (!((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null))
				{
					int num = Ids[index];
					string text = Names[index];
					if (((CharacterKnowledge)player.Inventory.SkillKnowledge).IsItemLearned(num))
					{
						return "Voce ja domina " + text + ".";
					}
					ResourcesPrefabManager instance = ResourcesPrefabManager.Instance;
					Item obj = ((instance != null) ? instance.GetItemPrefab(num) : null);
					Skill val = (Skill)(object)((obj is Skill) ? obj : null);
					if ((Object)(object)val == (Object)null)
					{
						return "Ainda nao tenho os ensinamentos de " + text + ". Confira se o mod da habilidade carregou.";
					}
					try
					{
						player.Inventory.TryUnlockSkill(val);
						if (!((CharacterKnowledge)player.Inventory.SkillKnowledge).IsItemLearned(num))
						{
							return "O treinamento nao foi concluido. Tente novamente em um instante.";
						}
						Plugin.Instance?.Log("APRENDIDA uid=" + UID.op_Implicit(player.UID) + ";id=" + num + ";nome=" + text);
						return "Treinamento concluido: " + text + ". A habilidade agora esta disponivel no seu livro.";
					}
					catch (Exception ex)
					{
						Plugin.Instance?.Log("FALHA id=" + num + ";erro=" + ex);
						return "O treinamento falhou sem alterar sua habilidade. Tente novamente.";
					}
				}
			}
			return "Nao consegui identificar quem esta treinando. Converse comigo novamente.";
		}
	}
}

BepInEx/plugins/Codex_Uivo_Loucura/CodexUivoLoucura.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using CodexHumanoidExtras;
using CodexSkillIcons;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Animation;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexHumanoidExtras
{
	internal sealed class PlaybackTail
	{
		private int emptySamples;

		internal float Elapsed { get; private set; }

		internal bool Observed { get; private set; }

		internal bool NativeEnded { get; private set; }

		internal bool CanRestore
		{
			get
			{
				if (NativeEnded && Observed)
				{
					return emptySamples >= 2;
				}
				return false;
			}
		}

		internal void EndNative()
		{
			NativeEnded = true;
		}

		internal void Sample(float delta, bool visible)
		{
			if (float.IsNaN(delta) || float.IsInfinity(delta) || delta < 0f)
			{
				throw new ArgumentOutOfRangeException("delta");
			}
			Elapsed += delta;
			Observed |= visible;
			emptySamples = ((NativeEnded && Observed && !visible) ? (emptySamples + 1) : 0);
		}

		internal bool TimedOut(float duration)
		{
			return Elapsed > duration * 4f + 2f;
		}
	}
	internal sealed class OverrideLease
	{
		private readonly Action<int, bool> _apply;

		private int _attempted;

		internal bool Active => _attempted > 0;

		internal OverrideLease(Action<int, bool> apply)
		{
			_apply = apply ?? throw new ArgumentNullException("apply");
		}

		internal void Acquire(int count)
		{
			if (Active || count < 1)
			{
				throw new InvalidOperationException("Invalid override lease");
			}
			try
			{
				for (int i = 0; i < count; i++)
				{
					_attempted = i + 1;
					_apply.Invoke(i, true);
				}
			}
			catch (Exception ex)
			{
				try
				{
					Release();
				}
				catch (Exception ex2)
				{
					throw new AggregateException(ex, ex2);
				}
				throw;
			}
		}

		internal void Release()
		{
			List<Exception> list = new List<Exception>();
			int num = 0;
			for (int num2 = _attempted - 1; num2 >= 0; num2--)
			{
				try
				{
					_apply.Invoke(num2, false);
				}
				catch (Exception item)
				{
					num = Math.Max(num, num2 + 1);
					list.Add(item);
				}
			}
			_attempted = num;
			if (list.Count > 0)
			{
				throw new AggregateException("Override restoration failed", list);
			}
		}
	}
}
namespace CodexSkillIcons
{
	internal static class SkillIcon
	{
		private static readonly HashSet<Sprite> owned = new HashSet<Sprite>();

		internal static Sprite Load(string folder, Func<Sprite> fallback, Action<string> warning)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = null;
			Sprite val2 = null;
			try
			{
				val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					name = "Codex_SkillIcon_Painted",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)2
				};
				if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, "UI", "skill-icon.png")), false) || ((Texture)val).width != 512 || ((Texture)val).height != 512)
				{
					throw new InvalidDataException("Expected512x512 skill-icon.png");
				}
				val.Apply(true, true);
				val2 = Sprite.Create(val, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidDataException("Icon Sprite unavailable");
				}
				owned.Add(val2);
				return val2;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				warning?.Invoke("ICON_FALLBACK:" + ex.Message);
				return fallback();
			}
		}

		internal static void Release(Sprite sprite)
		{
			if (!((Object)(object)sprite == (Object)null) && owned.Remove(sprite))
			{
				Object.Destroy((Object)(object)sprite.texture);
				Object.Destroy((Object)(object)sprite);
			}
		}
	}
}
namespace CodexUivoLoucura
{
	[BepInPlugin("codex.outward.uivo.loucura", "Codex - Uivo da Loucura", "1.1.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "codex.outward.uivo.loucura";

		public const int SkillId = 9106960;

		internal static ManualLogSource Log;

		private Skill prefab;

		private Harmony patches;

		private Sprite icon;

		private bool building;

		private readonly HashSet<int> rejected = new HashSet<int>();

		private void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			icon = SkillIcon.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (Func<Sprite>)UivoVisual.CreateIcon, (Action<string>)Log.LogWarning);
			patches = new Harmony("codex.outward.uivo.loucura");
			patches.PatchAll(typeof(Plugin).Assembly);
			UivoVisual.Paused = delegate
			{
				NetworkLevelLoader instance = NetworkLevelLoader.Instance;
				return instance != null && instance.IsGameplayPaused;
			};
			SL_Item.AddOnInstanceStartListener(9106960, (Action<Item>)Prepare);
			SL.OnPacksLoaded += Build;
			if (SL.PacksLoaded)
			{
				Build();
			}
			((MonoBehaviour)this).StartCoroutine(Learn());
			Log.LogMessage((object)"[UivoLoucura] 1.1.3;treinador;Agony;30s buff;+50percent damage dealt/received;purple skin/white hair;30vigor/50s;PENDING USER");
		}

		private void Build()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab != (Object)null || building)
			{
				return;
			}
			building = true;
			try
			{
				UivoClip.Build(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				UivoVisual.Ensure();
				UivoBuff.Build(icon);
				if ((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(9106960) != (Object)null)
				{
					throw new InvalidOperationException("Skill ID occupied:" + 9106960);
				}
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200310);
				AttackSkill val = (AttackSkill)(object)((itemPrefab is AttackSkill) ? itemPrefab : null);
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native template unavailable");
				}
				SL_AttackSkill val2 = new SL_AttackSkill();
				((SL_Item)val2).SerializeItem((Item)(object)val);
				((SL_Item)val2).New_ItemID = 9106960;
				((SL_Item)val2).LegacyItemID = -1;
				((SL_Item)val2).Name = "Uivo da Loucura";
				((SL_Item)val2).Description = "Ao concluir o uivo, recebe +50% de dano causado e +50% de dano recebido durante 30 segundos. Pele roxa, cabelo branco e particulas violetas temporarias. O uivo nao causa dano nem impacto.30vigor,50s recarga.";
				((SL_Item)val2).CastType = (SpellCastType)51;
				((SL_Item)val2).CastModifier = (SpellCastModifier)0;
				((SL_Item)val2).CastSheatheRequired = 0;
				((SL_Skill)val2).ManaCost = (((SL_Skill)val2).HealthCost = 0f);
				((SL_Skill)val2).StaminaCost = 30f;
				((SL_Skill)val2).Cooldown = 50f;
				((SL_Skill)val2).DurabilityCost = (((SL_Skill)val2).DurabilityCostPercent = 0f);
				((SL_Skill)val2).RequiredItems = (SkillItemReq[])(object)new SkillItemReq[0];
				val2.RequiredWeaponTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredOffHandTypes = (WeaponType[])(object)new WeaponType[0];
				val2.RequiredWeaponTags = new string[0];
				val2.RequireImbue = false;
				((SL_Item)val2).EffectBehaviour = (EditBehaviours)2;
				((SL_Item)val2).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[0];
				((SL_Skill)val2).StartVFX = (VFXPrefabs)0;
				((SL_Item)val2).OnTemplateApplied += Prepare;
				((ContentTemplate)val2).ApplyTemplate();
				ref Skill reference = ref prefab;
				Item currentPrefab = ((SL_Item)val2).CurrentPrefab;
				reference = (Skill)(object)((currentPrefab is Skill) ? currentPrefab : null);
				if ((Object)(object)prefab == (Object)null)
				{
					throw new InvalidOperationException("Skill creation failed");
				}
				Log.LogMessage((object)"[UivoLoucura] PRONTO:9106960;Human=True;Agony/buff only;30s;+50percent dealt/received;purple skin/white hair;30vigor/50s");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[UivoLoucura] INITFAILED:" + ex));
			}
			finally
			{
				building = false;
			}
		}

		private void Prepare(Item item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && item.ItemID == 9106960)
			{
				((Skill)item).StartVFX = null;
				CustomItemVisuals.SetSpriteLink(item, icon, false);
				CustomItemVisuals.SetSpriteLink(item, icon, true);
				AccessTools.Field(typeof(AttackSkill), "m_staminaConsumptionType").SetValue(item, (object)(StaminaConsumptionType)0);
			}
		}

		private IEnumerator Learn()
		{
			Character bound = null;
			UivoMotion boundMotion = null;
			int observedCount = -1;
			WaitForSeconds delay = new WaitForSeconds(3f);
			while (true)
			{
				CharacterManager instance = CharacterManager.Instance;
				DictionaryExt<string, Character> val = ((instance != null) ? instance.Characters : null);
				if ((Object)(object)bound == (Object)null || (Object)(object)boundMotion == (Object)null || val == null || val.Count != observedCount)
				{
					bound = null;
					boundMotion = null;
					if ((Object)(object)prefab != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
					{
						CharacterManager instance2 = CharacterManager.Instance;
						if (((instance2 != null) ? instance2.Characters : null) != null)
						{
							foreach (Character value in CharacterManager.Instance.Characters.Values)
							{
								if (!value.IsLocalPlayer)
								{
									continue;
								}
								CharacterInventory inventory = value.Inventory;
								if ((Object)(object)((inventory != null) ? inventory.SkillKnowledge : null) == (Object)null || (Object)(object)value.Animator == (Object)null || !value.Animator.isInitialized)
								{
									continue;
								}
								UivoMotion uivoMotion = ((Component)value).GetComponent<UivoMotion>();
								if ((Object)(object)uivoMotion == (Object)null)
								{
									try
									{
										uivoMotion = ((Component)value).gameObject.AddComponent<UivoMotion>();
										uivoMotion.Bind(value);
										rejected.Remove(((Object)value).GetInstanceID());
									}
									catch (Exception ex)
									{
										if ((Object)(object)uivoMotion != (Object)null)
										{
											Object.Destroy((Object)(object)uivoMotion);
										}
										if (rejected.Add(((Object)value).GetInstanceID()))
										{
											Log.LogWarning((object)("[UivoLoucura] AVATARREJECTED:" + ex.Message));
										}
										continue;
									}
								}
								bound = value;
								boundMotion = uivoMotion;
							}
						}
					}
					observedCount = val?.Count ?? (-1);
				}
				yield return delay;
			}
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Build;
			((MonoBehaviour)this).StopAllCoroutines();
			UivoMotion[] array = Object.FindObjectsOfType<UivoMotion>();
			foreach (UivoMotion obj in array)
			{
				obj.Cancel();
				Object.Destroy((Object)(object)obj);
			}
			UivoBuffController[] array2 = Object.FindObjectsOfType<UivoBuffController>();
			foreach (UivoBuffController obj2 in array2)
			{
				obj2.Shutdown();
				Object.Destroy((Object)(object)obj2);
			}
			Harmony obj3 = patches;
			if (obj3 != null)
			{
				obj3.UnpatchAll("codex.outward.uivo.loucura");
			}
			UivoClip.Dispose();
			UivoVisual.Release();
			SkillIcon.Release(icon);
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillStarted")]
	internal static class Started
	{
		private static bool Prefix(Skill __instance)
		{
			if (((Item)__instance).ItemID == 9106960)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				if (ownerCharacter == null)
				{
					return false;
				}
				return ((Component)ownerCharacter).GetComponent<UivoMotion>()?.Begin(__instance) == true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "SpellCast")]
	internal static class Cast
	{
		private static bool Prefix(Character __instance)
		{
			UivoMotion component = ((Component)__instance).GetComponent<UivoMotion>();
			if (!((Object)(object)component == (Object)null) && component.OwnCast)
			{
				return component.NativeInvocation;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Skill), "SkillEnded")]
	internal static class Ended
	{
		private static void Postfix(Skill __instance, bool _wasCancelled)
		{
			if (((Item)__instance).ItemID == 9106960)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				UivoMotion uivoMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<UivoMotion>() : null);
				if (_wasCancelled)
				{
					uivoMotion?.Cancel("native skill cancellation");
				}
				else
				{
					uivoMotion?.EndNative(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ForceCancel")]
	internal static class Interrupted
	{
		private static void Prefix(Character __instance)
		{
			((Component)__instance).GetComponent<UivoMotion>()?.Cancel("native interruption");
		}
	}
	[HarmonyPatch(typeof(Skill), "HasAllRequirements")]
	internal static class Requirements
	{
		private static void Postfix(Skill __instance, bool _tryingToActivate, ref bool __result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (__result && _tryingToActivate)
			{
				Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
				UivoMotion uivoMotion = ((ownerCharacter != null) ? ((Component)ownerCharacter).GetComponent<UivoMotion>() : null);
				if (((Item)__instance).ItemID == 9106960)
				{
					__result = uivoMotion?.CanBegin ?? false;
				}
				else if ((int)((Item)__instance).ActivateEffectAnimType == 51 && uivoMotion != null && uivoMotion.HasVisibleLease)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "AttackInput")]
	internal static class AttackWhileCasting
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			UivoMotion component = ((Component)__instance).GetComponent<UivoMotion>();
			if (component == null || !component.HasVisibleLease)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal enum UivoSurface
	{
		Skin,
		Hair
	}
	internal sealed class UivoAppearance : IDisposable
	{
		private sealed class Slot
		{
			internal Renderer Renderer;

			internal int Index;

			internal Material Original;

			internal Material Owned;

			internal bool Seen;
		}

		private sealed class Paint
		{
			internal Material Original;

			internal Material Owned;

			internal Texture2D Texture;

			internal UivoSurface Kind;
		}

		private readonly List<Slot> slots = new List<Slot>();

		private readonly List<Paint> paints = new List<Paint>();

		internal int SkinSlots { get; private set; }

		internal int HairSlots { get; private set; }

		internal void BeginRefresh()
		{
			int skinSlots = (HairSlots = 0);
			SkinSlots = skinSlots;
			foreach (Slot slot in slots)
			{
				slot.Seen = false;
			}
		}

		internal static bool SkinSlot(string name, bool nativeSkin, bool defaultFace, int index)
		{
			string text = (name ?? "").ToLowerInvariant();
			if (text.Contains("eye") || text.Contains("teeth") || text.Contains("hair"))
			{
				return false;
			}
			if (!nativeSkin && !text.Contains("_skin"))
			{
				if (defaultFace)
				{
					return index == 0;
				}
				return false;
			}
			return true;
		}

		internal void Apply(Renderer renderer, int index, UivoSurface kind)
		{
			//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_0123: Expected O, but got Unknown
			//IL_0160: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)renderer == (Object)null)
			{
				return;
			}
			Material[] sharedMaterials = renderer.sharedMaterials;
			if (index < 0 || index >= sharedMaterials.Length || (Object)(object)sharedMaterials[index] == (Object)null)
			{
				return;
			}
			for (int num = slots.Count - 1; num >= 0; num--)
			{
				Slot slot = slots[num];
				if (!((Object)(object)slot.Renderer != (Object)(object)renderer) && slot.Index == index)
				{
					if ((Object)(object)sharedMaterials[index] == (Object)(object)slot.Owned)
					{
						slot.Seen = true;
						Count(kind);
						return;
					}
					slots.RemoveAt(num);
				}
			}
			Material val = sharedMaterials[index];
			Paint paint = null;
			foreach (Paint paint2 in paints)
			{
				if ((Object)(object)paint2.Original == (Object)(object)val && paint2.Kind == kind)
				{
					paint = paint2;
					break;
				}
			}
			if (paint == null)
			{
				paint = new Paint
				{
					Original = val,
					Owned = new Material(val)
					{
						name = "Loucura_Private_" + kind
					},
					Kind = kind
				};
				paints.Add(paint);
				Color val2 = ((kind == UivoSurface.Hair) ? new Color(0.95f, 0.97f, 1f) : new Color(0.64f, 0.14f, 0.88f));
				string text = (paint.Owned.HasProperty("_MainTex") ? "_MainTex" : (paint.Owned.HasProperty("_BaseMap") ? "_BaseMap" : null));
				Texture val3 = ((text != null) ? paint.Owned.GetTexture(text) : null);
				if ((Object)(object)val3 != (Object)null)
				{
					paint.Texture = Recolor(val3, kind, val2);
					paint.Owned.SetTexture(text, (Texture)(object)paint.Texture);
					val2 = Color.white;
				}
				string[] array = new string[3] { "_Color", "_BaseColor", "_TintColor" };
				foreach (string text2 in array)
				{
					if (paint.Owned.HasProperty(text2))
					{
						val2.a = paint.Owned.GetColor(text2).a;
						paint.Owned.SetColor(text2, val2);
					}
				}
			}
			sharedMaterials[index] = paint.Owned;
			renderer.sharedMaterials = sharedMaterials;
			slots.Add(new Slot
			{
				Renderer = renderer,
				Index = index,
				Original = val,
				Owned = paint.Owned,
				Seen = true
			});
			Count(kind);
		}

		private void Count(UivoSurface kind)
		{
			if (kind == UivoSurface.Hair)
			{
				HairSlots++;
			}
			else
			{
				SkinSlots++;
			}
		}

		private static Texture2D Recolor(Texture source, UivoSurface kind, Color color)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_008f: 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_00f8: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			int num = Math.Min(1024, source.width);
			int num2 = Math.Min(1024, source.height);
			RenderTexture active = RenderTexture.active;
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)1);
			Texture2D val = null;
			try
			{
				Graphics.Blit(source, temporary);
				RenderTexture.active = temporary;
				val = new Texture2D(num, num2, (TextureFormat)4, true, true)
				{
					name = "Loucura_PrivateTexture_" + kind,
					wrapMode = source.wrapMode,
					filterMode = (FilterMode)2
				};
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
				val.Apply(false, false);
				Color[] pixels = val.GetPixels();
				for (int i = 0; i < pixels.Length; i++)
				{
					float num3 = Mathf.Clamp01(((Color)(ref pixels[i])).grayscale);
					float num4 = ((kind == UivoSurface.Hair) ? (0.65f + 0.35f * num3) : (0.35f + 0.65f * num3));
					pixels[i] = new Color(color.r * num4, color.g * num4, color.b * num4, pixels[i].a);
				}
				val.SetPixels(pixels);
				val.Apply(true, true);
				return val;
			}
			catch
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				throw;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		internal void EndRefresh()
		{
			for (int num = slots.Count - 1; num >= 0; num--)
			{
				if (!slots[num].Seen)
				{
					Restore(slots[num]);
					slots.RemoveAt(num);
				}
			}
			for (int num2 = paints.Count - 1; num2 >= 0; num2--)
			{
				bool flag = false;
				foreach (Slot slot in slots)
				{
					flag |= (Object)(object)slot.Owned == (Object)(object)paints[num2].Owned;
				}
				if (!flag)
				{
					Destroy(paints[num2]);
					paints.RemoveAt(num2);
				}
			}
		}

		private static void Restore(Slot slot)
		{
			if (!((Object)(object)slot.Renderer == (Object)null))
			{
				Material[] sharedMaterials = slot.Renderer.sharedMaterials;
				if (slot.Index < sharedMaterials.Length && (Object)(object)sharedMaterials[slot.Index] == (Object)(object)slot.Owned)
				{
					sharedMaterials[slot.Index] = slot.Original;
					slot.Renderer.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static void Destroy(Paint paint)
		{
			if ((Object)(object)paint.Owned != (Object)null)
			{
				Object.Destroy((Object)(object)paint.Owned);
			}
			if ((Object)(object)paint.Texture != (Object)null)
			{
				Object.Destroy((Object)(object)paint.Texture);
			}
		}

		public void Dispose()
		{
			foreach (Slot slot in slots)
			{
				Restore(slot);
			}
			slots.Clear();
			foreach (Paint paint in paints)
			{
				Destroy(paint);
			}
			paints.Clear();
			int skinSlots = (HairSlots = 0);
			SkinSlots = skinSlots;
		}
	}
	internal static class UivoBuff
	{
		internal const string Identifier = "Codex.Loucura.Transfiguracao";

		internal const float Duration = 30f;

		private static StatusEffect prefab;

		internal static void Build(Sprite icon)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)prefab != (Object)null))
			{
				if ((Object)(object)ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Codex.Loucura.Transfiguracao") != (Object)null)
				{
					throw new InvalidOperationException("Buff identifier occupied:Codex.Loucura.Transfiguracao");
				}
				((ContentTemplate)new SL_StatusEffect
				{
					TargetStatusIdentifier = "Defense Bonus",
					StatusIdentifier = "Codex.Loucura.Transfiguracao",
					Name = "Loucura Desperta",
					Description = "+50% de dano causado e +50% de dano recebido. Pele roxa e cabelo branco.30 segundos.",
					Lifespan = 30f,
					DisplayedInHUD = true,
					IsHidden = false,
					IsMalusEffect = false,
					Purgeable = true,
					PlayFXOnActivation = false,
					PlaySpecialFXOnStop = false,
					Tags = new string[0],
					EffectBehaviour = (EditBehaviours)2,
					Effects = (SL_EffectTransform[])(object)new SL_EffectTransform[0]
				}).ApplyTemplate();
				prefab = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Codex.Loucura.Transfiguracao");
				if ((Object)(object)prefab == (Object)null || prefab.StatusData == null || prefab.StatusData.LifeSpan != 30f)
				{
					throw new InvalidOperationException("Buff creation failed");
				}
				prefab.OverrideIcon = icon;
			}
		}

		internal static bool Active(Character owner)
		{
			if ((Object)(object)owner == (Object)null || !owner.IsLocalPlayer || !owner.Alive)
			{
				return false;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsOverallLoadingDone)
			{
				StatusEffectManager statusEffectMngr = owner.StatusEffectMngr;
				if (statusEffectMngr == null)
				{
					return false;
				}
				StatusEffect statusEffectOfName = statusEffectMngr.GetStatusEffectOfName("Codex.Loucura.Transfiguracao");
				return ((statusEffectOfName != null) ? new bool?(statusEffectOfName.IsActive) : ((bool?)null)) == true;
			}
			return false;
		}

		internal static bool Apply(Character owner)
		{
			if ((Object)(object)prefab == (Object)null || (Object)(object)owner == (Object)null || !owner.IsLocalPlayer || !owner.Alive || (Object)(object)owner.StatusEffectMngr == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[UivoLoucura] BUFF_REJECTED;prefab/owner/local/alive/manager invalid");
				return false;
			}
			Remove(owner);
			if ((Object)(object)owner.StatusEffectMngr.AddStatusEffect(prefab, owner) == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[UivoLoucura] BUFF_REJECTED;native status manager declined application");
				return false;
			}
			(((Component)owner).GetComponent<UivoBuffController>() ?? ((Component)owner).gameObject.AddComponent<UivoBuffController>()).Bind(owner);
			Plugin.Log.LogMessage((object)"[UivoLoucura] BUFF_APPLIED;30s;1.5dealt/1.5received;purpleSkin/whiteHair;no stacking/no wave");
			return true;
		}

		internal static void Remove(Character owner)
		{
			if ((Object)(object)owner != (Object)null && (Object)(object)owner.StatusEffectMngr != (Object)null)
			{
				owner.StatusEffectMngr.RemoveStatusWithIdentifierName("Codex.Loucura.Transfiguracao");
			}
		}
	}
	public sealed class UivoBuffController : MonoBehaviour
	{
		private Character owner;

		private GameObject aura;

		private UivoAppearance appearance;

		private float refresh;

		private bool logged;

		private static readonly FieldInfo Skin = AccessTools.Field(typeof(CharacterVisuals), "m_skinMat");

		private static readonly FieldInfo Head = AccessTools.Field(typeof(CharacterVisuals), "m_defaultHeadVisuals");

		private static readonly FieldInfo Hair = AccessTools.Field(typeof(CharacterVisuals), "m_defaultHairVisuals");

		internal void Bind(Character value)
		{
			StopVisuals();
			owner = value;
			refresh = 0f;
			logged = false;
		}

		private void Update()
		{
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)owner == (Object)null || !owner.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone)
			{
				Shutdown();
			}
			else if (!UivoBuff.Active(owner))
			{
				StopVisuals();
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				try
				{
					if ((Object)(object)aura == (Object)null && (Object)(object)owner.Animator != (Object)null)
					{
						aura = UivoVisual.AttachBuff(owner.Animator, ((Component)owner).transform);
					}
					refresh -= Time.deltaTime;
					if (!(refresh > 0f))
					{
						refresh = 0.5f;
						RefreshAppearance();
					}
				}
				catch (Exception ex)
				{
					StopVisuals();
					UivoBuff.Remove(owner);
					Plugin.Log.LogError((object)("[UivoLoucura] BUFF_VISUAL_FAILED:" + ex));
				}
			}
		}

		private void RefreshAppearance()
		{
			CharacterVisuals visuals = owner.Visuals;
			if ((Object)(object)visuals == (Object)null)
			{
				return;
			}
			if (appearance == null)
			{
				appearance = new UivoAppearance();
			}
			appearance.BeginRefresh();
			object? value = Skin.GetValue(visuals);
			Material val = (Material)((value is Material) ? value : null);
			object? value2 = Head.GetValue(visuals);
			ArmorVisuals val2 = (ArmorVisuals)((value2 is ArmorVisuals) ? value2 : null);
			object? value3 = Hair.GetValue(visuals);
			ArmorVisuals val3 = (ArmorVisuals)((value3 is ArmorVisuals) ? value3 : null);
			SkinnedMeshRenderer val4 = (((Object)(object)val2 != (Object)null) ? val2.Renderer : null);
			SkinnedMeshRenderer val5 = (((Object)(object)val3 != (Object)null) ? val3.Renderer : null);
			SkinnedMeshRenderer[] componentsInChildren = ((Component)visuals).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val6 in componentsInChildren)
			{
				Material[] sharedMaterials = ((Renderer)val6).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)val6 == (Object)(object)val5)
					{
						appearance.Apply((Renderer)(object)val6, j, UivoSurface.Hair);
					}
					else if ((Object)(object)sharedMaterials[j] != (Object)null && UivoAppearance.SkinSlot(((Object)sharedMaterials[j]).name, (Object)(object)sharedMaterials[j] == (Object)(object)val, (Object)(object)val6 == (Object)(object)val4, j))
					{
						appearance.Apply((Renderer)(object)val6, j, UivoSurface.Skin);
					}
				}
			}
			appearance.EndRefresh();
			if (!logged)
			{
				Plugin.Log.LogMessage((object)("[UivoLoucura] TRANSFORM;skinSlots=" + appearance.SkinSlots + ";whiteHairSlots=" + appearance.HairSlots + ";armor unchanged"));
				logged = true;
			}
		}

		private void StopVisuals()
		{
			appearance?.Dispose();
			appearance = null;
			if ((Object)(object)aura != (Object)null)
			{
				Object.Destroy((Object)(object)aura);
				aura = null;
			}
		}

		internal void Shutdown()
		{
			StopVisuals();
			UivoBuff.Remove(owner);
		}

		private void OnDisable()
		{
			Shutdown();
		}

		private void OnDestroy()
		{
			Shutdown();
		}
	}
	internal static class UivoClip
	{
		internal const string Prefix = "UivoLoucuraHumanoid_";

		internal const float Duration = 3.7f;

		internal const string Hash = "1251209BB912D73E0FB17D6BE7CFAD382026FE58BA0FFEFEC5BBF0D53E23E1DA";

		internal static readonly List<AnimationOverride> Overrides = new List<AnimationOverride>();

		private static readonly List<AnimationClip> copies = new List<AnimationClip>();

		private static AssetBundle bundle;

		internal static bool Ready => Overrides.Count == 3;

		internal unsafe static void Build(string folder)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			try
			{
				string text = Path.Combine(folder, "Assets", "codex_uivo_loucura");
				using (SHA256 sHA = SHA256.Create())
				{
					if (BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(text))).Replace("-", "") != "1251209BB912D73E0FB17D6BE7CFAD382026FE58BA0FFEFEC5BBF0D53E23E1DA")
					{
						throw new InvalidDataException("Compiled punch SHA256 mismatch");
					}
				}
				bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new InvalidDataException("Compiled punch bundle unavailable");
				}
				AnimationClip val = bundle.LoadAllAssets<AnimationClip>().Single((AnimationClip c) => ((Object)c).name == "CodexLoucura_Agony");
				if (val.legacy || !((Motion)val).isHumanMotion || Math.Abs(val.length - 3.7f) > 0.001f)
				{
					throw new InvalidDataException("Expected external Agony Human motion with skinned reference");
				}
				PlayerAnimationClip[] array = new PlayerAnimationClip[3];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAnimationClip[] array2 = (PlayerAnimationClip[])(object)array;
				for (int num = 0; num < array2.Length; num++)
				{
					PlayerAnimationClip val2 = array2[num];
					AnimationClip val3 = Object.Instantiate<AnimationClip>(val);
					copies.Add(val3);
					((Object)val3).name = "UivoLoucuraHumanoid_" + ((object)(*(PlayerAnimationClip*)(&val2))/*cast due to .constrained prefix*/).ToString();
					val3.events = (AnimationEvent[])(object)new AnimationEvent[0];
					CustomAnimations.CopyAnimationEvents(CustomAnimations.GetOriginalClip(val2), val3);
					Overrides.Add(new AnimationOverride(val2, val3, false));
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		internal static void Dispose()
		{
			Overrides.Clear();
			foreach (AnimationClip copy in copies)
			{
				if ((Object)(object)copy != (Object)null)
				{
					Object.Destroy((Object)(object)copy);
				}
			}
			copies.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
			}
			bundle = null;
		}
	}
	internal static class UivoDamage
	{
		internal struct Scope
		{
			internal Character Dealer;

			internal bool Replay;

			internal bool Scaled;
		}

		[ThreadStatic]
		internal static Character Dealer;

		[ThreadStatic]
		internal static bool Replay;

		[ThreadStatic]
		internal static bool Scaled;

		internal static readonly FieldInfo Owner = AccessTools.Field(typeof(CharacterStats), "m_character");

		internal static float Scale(float amount, bool outgoing, bool incoming, bool replay = false)
		{
			if (replay || amount <= 0f || float.IsNaN(amount) || float.IsInfinity(amount))
			{
				return amount;
			}
			return amount * (outgoing ? 1.5f : 1f) * (incoming ? 1.5f : 1f);
		}

		internal static Scope Enter(Character dealer, bool replay = false)
		{
			Scope result = Snapshot();
			Dealer = dealer;
			Replay = replay || result.Replay;
			Scaled = false;
			return result;
		}

		internal static Scope Snapshot()
		{
			return new Scope
			{
				Dealer = Dealer,
				Replay = Replay,
				Scaled = Scaled
			};
		}

		internal static void Restore(Scope old)
		{
			Dealer = old.Dealer;
			Replay = old.Replay;
			Scaled = old.Scaled;
		}

		internal static float Loss(Character target, float amount)
		{
			return Scale(amount, UivoBuff.Active(Dealer), UivoBuff.Active(target), Replay);
		}
	}
	[HarmonyPatch(typeof(Character), "ReceiveDamage", new Type[]
	{
		typeof(float),
		typeof(Vector3),
		typeof(bool)
	})]
	internal static class NativeDamagePayload
	{
		private static void Prefix(Character __instance, ref float __0, out UivoDamage.Scope __state)
		{
			__state = UivoDamage.Snapshot();
			__0 = UivoDamage.Loss(__instance, __0);
			UivoDamage.Scaled = true;
		}

		private static Exception Finalizer(Exception __exception, UivoDamage.Scope __state)
		{
			UivoDamage.Restore(__state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(Character), "VitalityHit", new Type[]
	{
		typeof(Character),
		typeof(float),
		typeof(Vector3)
	})]
	internal static class DamageSource
	{
		private static void Prefix(Character _dealerChar, out UivoDamage.Scope __state)
		{
			__state = UivoDamage.Enter(_dealerChar);
		}

		private static Exception Finalizer(Exception __exception, UivoDamage.Scope __state)
		{
			UivoDamage.Restore(__state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(Character), "SendDamage")]
	internal static class DamageReplay
	{
		private static void Prefix(out UivoDamage.Scope __state)
		{
			__state = UivoDamage.Enter(null, replay: true);
		}

		private static Exception Finalizer(Exception __exception, UivoDamage.Scope __state)
		{
			UivoDamage.Restore(__state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(Skill), "ConsumeResources")]
	internal static class ResourceCost
	{
		private static void Prefix(out UivoDamage.Scope __state)
		{
			__state = UivoDamage.Enter(null, replay: true);
		}

		private static Exception Finalizer(Exception __exception, UivoDamage.Scope __state)
		{
			UivoDamage.Restore(__state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(CharacterStats), "ReceiveDamage", new Type[] { typeof(float) })]
	internal static class FinalHealthDamage
	{
		private static void Prefix(CharacterStats __instance, ref float __0)
		{
			if (!UivoDamage.Scaled)
			{
				object? value = UivoDamage.Owner.GetValue(__instance);
				__0 = UivoDamage.Loss((Character)((value is Character) ? value : null), __0);
			}
		}
	}
	[HarmonyPatch(typeof(AffectHealth), "ActivateLocally", new Type[]
	{
		typeof(Character),
		typeof(object[])
	})]
	internal static class HealthEffectSource
	{
		private static void Prefix(AffectHealth __instance, out UivoDamage.Scope __state)
		{
			__state = UivoDamage.Enter(((Effect)__instance).SourceCharacter);
		}

		private static Exception Finalizer(Exception __exception, UivoDamage.Scope __state)
		{
			UivoDamage.Restore(__state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(CharacterStats), "AffectHealth", new Type[] { typeof(float) })]
	internal static class FinalHealthEffect
	{
		private static void Prefix(CharacterStats __instance, ref float __0)
		{
			if (__0 < 0f)
			{
				object? value = UivoDamage.Owner.GetValue(__instance);
				__0 = 0f - UivoDamage.Loss((Character)((value is Character) ? value : null), 0f - __0);
			}
		}
	}
	public sealed class UivoMotion : MonoBehaviour
	{
		private Character player;

		private Avatar avatar;

		private Skill skill;

		private OverrideLease lease;

		private PlaybackTail tail;

		private UivoTimeline clock;

		private bool nativeCast;

		private float normalized;

		private GameObject aura;

		internal bool NativeInvocation { get; private set; }

		internal bool Active => (Object)(object)skill != (Object)null;

		internal bool HasVisibleLease
		{
			get
			{
				if (lease != null)
				{
					return lease.Active;
				}
				return false;
			}
		}

		internal bool OwnCast
		{
			get
			{
				if (Active && (Object)(object)player != (Object)null)
				{
					return (Object)(object)player.CastReceiver == (Object)(object)((Component)skill).gameObject;
				}
				return false;
			}
		}

		internal bool CanBegin
		{
			get
			{
				if (UivoClip.Ready && !Active && !HasVisibleLease && (Object)(object)player != (Object)null && player.IsLocalPlayer && player.Alive && !player.Falling && !player.Sliding && (Object)(object)player.CharacterController != (Object)null && ((Collider)player.CharacterController).enabled)
				{
					return (Object)(object)player.Animator.avatar == (Object)(object)avatar;
				}
				return false;
			}
		}

		internal void Bind(Character value)
		{
			if ((Object)(object)value.Animator == (Object)null || !value.Animator.isHuman || (Object)(object)value.Animator.avatar == (Object)null || !value.Animator.avatar.isValid)
			{
				throw new InvalidOperationException("Native Human Avatar invalid");
			}
			player = value;
			avatar = value.Animator.avatar;
			lease = new OverrideLease(delegate(int i, bool on)
			{
				UivoClip.Overrides[i].SetForCharacter(player, on);
			});
		}

		internal bool Begin(Skill value)
		{
			if (((Item)value).ItemID != 9106960 || !CanBegin)
			{
				return false;
			}
			try
			{
				lease.Acquire(UivoClip.Overrides.Count);
				skill = value;
				tail = new PlaybackTail();
				clock = new UivoTimeline();
				nativeCast = false;
				normalized = 0f;
				Plugin.Log.LogMessage((object)("[UivoLoucura] CAST;Agony;nativeAvatar=" + ((Object)avatar).name + ";30vigor/50s"));
				return true;
			}
			catch (Exception ex)
			{
				Fail("OVERRIDEFAILED:" + ex);
				return false;
			}
		}

		internal void EndNative(Skill value)
		{
			if (Active && !((Object)(object)value != (Object)(object)skill) && !tail.NativeEnded)
			{
				tail.EndNative();
				Plugin.Log.LogMessage((object)"[UivoLoucura] NATIVEEND;retain override through blend-out");
			}
		}

		private void LateUpdate()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				if (HasVisibleLease)
				{
					Cancel("retry restoration");
				}
				return;
			}
			NetworkLevelLoader instance = NetworkLevelLoader.Instance;
			if ((Object)(object)player == (Object)null || !player.Alive || (Object)(object)instance == (Object)null || !instance.IsOverallLoadingDone || (Object)(object)player.Animator.avatar != (Object)(object)avatar)
			{
				Cancel("death/loading/avatar");
			}
			else if (!OwnCast && !tail.NativeEnded)
			{
				Cancel("interrupted receiver");
			}
			else
			{
				if (instance.IsGameplayPaused)
				{
					return;
				}
				bool flag = false;
				bool observed = tail.Observed;
				for (int i = 0; i < player.Animator.layerCount; i++)
				{
					bool num = flag;
					AnimatorClipInfo[] currentAnimatorClipInfo = player.Animator.GetCurrentAnimatorClipInfo(i);
					AnimatorStateInfo val = player.Animator.GetCurrentAnimatorStateInfo(i);
					flag = num | Sample(currentAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					if (player.Animator.IsInTransition(i))
					{
						bool num2 = flag;
						AnimatorClipInfo[] nextAnimatorClipInfo = player.Animator.GetNextAnimatorClipInfo(i);
						val = player.Animator.GetNextAnimatorStateInfo(i);
						flag = num2 | Sample(nextAnimatorClipInfo, ((AnimatorStateInfo)(ref val)).normalizedTime);
					}
				}
				tail.Sample(Time.deltaTime, flag);
				if (!observed && tail.Observed)
				{
					Plugin.Log.LogMessage((object)"[UivoLoucura] EXTERNALACTIVE;Human=True;AvatarUNCHANGED");
				}
				if (flag)
				{
					try
					{
						clock.Observe(normalized);
						if (clock.Started && !nativeCast)
						{
							if (!OwnCast)
							{
								Fail("Native receiver lost before cost");
								return;
							}
							NativeInvocation = true;
							nativeCast = true;
							((Component)player).gameObject.SendMessage("SpellCast", (SendMessageOptions)1);
							NativeInvocation = false;
							if (!Active || !OwnCast)
							{
								return;
							}
							try
							{
								aura = UivoVisual.Attach(player.Animator, ((Component)player).transform);
							}
							catch (Exception ex)
							{
								Plugin.Log.LogWarning((object)("[UivoLoucura] AURAFX_FAILED:" + ex.Message));
							}
						}
					}
					catch (Exception ex2)
					{
						Fail("RELEASEFAILED:" + ex2);
						return;
					}
					finally
					{
						NativeInvocation = false;
					}
				}
				if (tail.CanRestore)
				{
					bool flag2 = clock.CanGrant(nativeCast, tail.CanRestore);
					Plugin.Log.LogMessage((object)("[UivoLoucura] BUFF_FINISH;stateProgress=" + normalized + ";nativeCast=" + nativeCast + ";eligible=" + flag2));
					Cancel("native blend-out complete");
					if (flag2)
					{
						try
						{
							UivoBuff.Apply(player);
						}
						catch (Exception ex3)
						{
							Plugin.Log.LogError((object)("[UivoLoucura] BUFF_APPLY_FAILED:" + ex3));
						}
					}
				}
				else if (tail.TimedOut(3.7f))
				{
					Fail("External clip/transition timeout");
				}
			}
		}

		private bool Sample(AnimatorClipInfo[] clips, float progress)
		{
			//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)
			bool result = false;
			for (int i = 0; i < clips.Length; i++)
			{
				AnimatorClipInfo val = clips[i];
				if (((AnimatorClipInfo)(ref val)).weight > 0.0001f && (Object)(object)((AnimatorClipInfo)(ref val)).clip != (Object)null && ((Object)((AnimatorClipInfo)(ref val)).clip).name.StartsWith("UivoLoucuraHumanoid_", StringComparison.Ordinal))
				{
					result = true;
					normalized = Math.Max(normalized, progress);
				}
			}
			return result;
		}

		private void Fail(string reason)
		{
			bool ownCast = OwnCast;
			Plugin.Log.LogError((object)("[UivoLoucura] FAILED:" + reason));
			Cancel("failure");
			if (ownCast && (Object)(object)player != (Object)null && player.Alive)
			{
				player.ForceCancel(true, true);
			}
		}

		internal void Cancel(string reason = "shutdown")
		{
			clock?.Cancel();
			bool active = Active;
			skill = null;
			tail = null;
			clock = null;
			nativeCast = false;
			if ((Object)(object)aura != (Object)null)
			{
				Object.Destroy((Object)(object)aura);
				aura = null;
			}
			try
			{
				lease?.Release();
				if (active)
				{
					Plugin.Log.LogMessage((object)("[UivoLoucura] RESTORED;reason=" + reason + ";AvatarUNCHANGED"));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[UivoLoucura] RESTOREFAILED:" + ex));
			}
		}

		private void OnDisable()
		{
			Cancel();
		}

		private void OnDestroy()
		{
			Cancel();
		}
	}
	internal sealed class UivoTimeline
	{
		internal const float StartAt = 1f / 111f;

		private float progress;

		private bool cancelled;

		internal bool Started
		{
			get
			{
				if (!cancelled)
				{
					return progress >= 1f / 111f;
				}
				return false;
			}
		}

		internal bool CanGrant(bool nativeCast, bool recovered)
		{
			return Started && nativeCast && recovered;
		}

		internal void Observe(float value)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			if (!cancelled)
			{
				progress = Math.Max(progress, value);
			}
		}

		internal void Cancel()
		{
			cancelled = true;
		}
	}
	internal static class UivoVisual
	{
		internal static Func<bool> Paused;

		internal static readonly HashSet<UivoAura> Auras = new HashSet<UivoAura>();

		internal static readonly HashSet<UivoBuffAura> BuffAuras = new HashSet<UivoBuffAura>();

		private static Texture2D soft;

		private static Texture2D iconTexture;

		private static Material mist;

		private static Material energy;

		private static Sprite icon;

		internal static void Ensure()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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)
			if ((Object)(object)soft != (Object)null)
			{
				return;
			}
			Shader val = Shader.Find("Legacy Shaders/Particles/Alpha Blended");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Aura shader unavailable");
			}
			soft = new Texture2D(512, 512, (TextureFormat)4, true)
			{
				name = "Loucura_SoftRound",
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[262144];
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 512; j++)
				{
					float num = ((float)j - 255.5f) / 255.5f;
					float num2 = ((float)i - 255.5f) / 255.5f;
					array[i * 512 + j] = Color32.op_Implicit(new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Max(0f, 1f - num * num - num2 * num2), 3f)));
				}
			}
			soft.SetPixels32(array);
			soft.Apply(true, true);
			mist = new Material(val)
			{
				name = "Loucura_SharedMist",
				mainTexture = (Texture)(object)soft
			};
			mist.SetColor("_TintColor", new Color(0.8f, 0.45f, 1f, 0.4f));
			Shader obj = Shader.Find("Legacy Shaders/Particles/Additive");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("Pulse shader unavailable");
			}
			energy = new Material(obj)
			{
				name = "Loucura_SharedPulse",
				mainTexture = (Texture)(object)soft
			};
			energy.SetColor("_TintColor", new Color(0.85f, 0.1f, 1f, 0.6f));
		}

		internal static GameObject Attach(Animator source, Transform owner)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Loucura_AuraDuranteCast");
			val.transform.SetParent(owner, false);
			val.AddComponent<UivoAura>().Bind(source);
			return val;
		}

		internal static ParticleSystem Smoke(Transform parent)
		{
			//IL_0005: 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_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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("VaporRoxo");
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.25f, 0.6f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.12f, 0.3f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.05f, 0.25f);
			((MainModule)(ref main)).maxParticles = 16;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.55f, 0.12f, 0.8f, 0.32f));
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(12f);
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.055f;
			VelocityOverLifetimeModule velocityOverLifetime = val2.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = MinMaxCurve.op_Implicit(0.22f);
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(0.9f, 0.5f, 1f), 0f),
				new GradientColorKey(new Color(0.3f, 0.02f, 0.7f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(0.6f, 0.2f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
			((Renderer)((Component)val2).GetComponent<ParticleSystemRenderer>()).sharedMaterial = mist;
			val2.Play();
			return val2;
		}

		internal static LineRenderer Line(Transform parent, string name, int points)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			obj.positionCount = points;
			obj.useWorldSpace = false;
			((Renderer)obj).sharedMaterial = energy;
			obj.widthMultiplier = 0.038f;
			obj.startColor = new Color(0.9f, 0.3f, 1f, 0.65f);
			obj.endColor = new Color(0.4f, 0.05f, 1f, 0.35f);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return obj;
		}

		internal static GameObject AttachBuff(Animator source, Transform owner)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			Ensure();
			GameObject val = new GameObject("Loucura_Transfiguracao30s");
			val.transform.SetParent(owner, false);
			val.AddComponent<UivoBuffAura>().Bind(source);
			return val;
		}

		internal static Sprite CreateIcon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_00fa: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)icon != (Object)null)
			{
				return icon;
			}
			iconTexture = new Texture2D(128, 128, (TextureFormat)4, true);
			Color32[] array = (Color32[])(object)new Color32[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j - 63.5f) / 63.5f;
					float num2 = ((float)i - 63.5f) / 63.5f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					array[i * 128 + j] = Color32.op_Implicit(new Color(0.8f, 0.2f, 1f, Mathf.Clamp01(1f - Mathf.Abs(num3 - 0.6f) * 25f)));
				}
			}
			iconTexture.SetPixels32(array);
			iconTexture.Apply(true, true);
			icon = Sprite.Create(iconTexture, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 128f);
			return icon;
		}

		internal static void Release()
		{
			foreach (UivoAura item in new List<UivoAura>(Auras))
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			foreach (UivoBuffAura item2 in new List<UivoBuffAura>(BuffAuras))
			{
				if ((Object)(object)item2 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item2).gameObject);
				}
			}
			Auras.Clear();
			BuffAuras.Clear();
			Object[] array = (Object[])(object)new Object[5]
			{
				(Object)soft,
				(Object)mist,
				(Object)energy,
				(Object)iconTexture,
				(Object)icon
			};
			foreach (Object val in array)
			{
				if (val != (Object)null)
				{
					Object.Destroy(val);
				}
			}
			soft = (iconTexture = null);
			mist = (energy = null);
			icon = null;
		}
	}
	public sealed class UivoAura : MonoBehaviour
	{
		private Animator source;

		private Transform head;

		private Transform left;

		private Transform right;

		private ParticleSystem[] smoke;

		private LineRenderer[] arcs;

		private float age;

		private bool paused;

		internal void Bind(Animator animator)
		{
			source = animator;
			head = source.GetBoneTransform((HumanBodyBones)10);
			left = source.GetBoneTransform((HumanBodyBones)17);
			right = source.GetBoneTransform((HumanBodyBones)18);
			smoke = (ParticleSystem[])(object)new ParticleSystem[3]
			{
				UivoVisual.Smoke(((Component)this).transform),
				UivoVisual.Smoke(((Component)this).transform),
				UivoVisual.Smoke(((Component)this).transform)
			};
			arcs = (LineRenderer[])(object)new LineRenderer[6];
			for (int i = 0; i < 6; i++)
			{
				arcs[i] = UivoVisual.Line(((Component)this).transform, "FaiscaRoxa", 9);
				arcs[i].useWorldSpace = true;
			}
			UivoVisual.Auras.Add(this);
			Sample(0f);
		}

		internal void Sample(float time)
		{
			//IL_003a: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)head == (Object)null)
			{
				return;
			}
			Vector3 val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.forward : ((Component)this).transform.forward);
			((Component)smoke[0]).transform.position = head.position + val * 0.13f;
			((Component)smoke[1]).transform.position = (((Object)(object)left != (Object)null) ? left.position : head.position);
			((Component)smoke[2]).transform.position = (((Object)(object)right != (Object)null) ? right.position : head.position);
			for (int i = 0; i < arcs.Length; i++)
			{
				for (int j = 0; j < 9; j++)
				{
					float num = (float)j / 8f;
					float num2 = (float)i * (float)Math.PI / 3f + num * 2.3f + time * 2f;
					float num3 = 0.16f + 0.025f * Mathf.Sin((float)j * 2.8f + time * 30f);
					arcs[i].SetPosition(j, head.position + new Vector3(Mathf.Cos(num2) * num3, (num - 0.5f) * 0.35f, Mathf.Sin(num2) * num3) + val * 0.1f);
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)source == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			bool flag = UivoVisual.Paused?.Invoke() ?? false;
			if (flag != paused)
			{
				ParticleSystem[] array = smoke;
				foreach (ParticleSystem val in array)
				{
					if (flag)
					{
						val.Pause();
					}
					else
					{
						val.Play();
					}
				}
				paused = flag;
			}
			if (!flag)
			{
				age += Time.deltaTime;
				Sample(age);
			}
		}

		private void OnDestroy()
		{
			UivoVisual.Auras.Remove(this);
		}
	}
	public sealed class UivoBuffAura : MonoBehaviour
	{
		private Animator source;

		private Transform chest;

		private Transform head;

		private Transform left;

		private Transform right;

		private ParticleSystem[] wisps;

		private LineRenderer[] sparks;

		private float age;

		private bool paused;

		internal void Bind(Animator animator)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			source = animator;
			chest = source.GetBoneTransform((HumanBodyBones)8) ?? source.GetBoneTransform((HumanBodyBones)0);
			head = source.GetBoneTransform((HumanBodyBones)10);
			left = source.GetBoneTransform((HumanBodyBones)17);
			right = source.GetBoneTransform((HumanBodyBones)18);
			wisps = (ParticleSystem[])(object)new ParticleSystem[4]
			{
				UivoVisual.Smoke(((Component)this).transform),
				UivoVisual.Smoke(((Component)this).transform),
				UivoVisual.Smoke(((Component)this).transform),
				UivoVisual.Smoke(((Component)this).transform)
			};
			ParticleSystem[] array = wisps;
			foreach (ParticleSystem obj in array)
			{
				MainModule main = obj.main;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 1.2f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.06f, 0.16f);
				((MainModule)(ref main)).maxParticles = 18;
				EmissionModule emission = obj.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(8f);
				ShapeModule shape = obj.shape;
				((ShapeModule)(ref shape)).radius = 0.09f;
			}
			sparks = (LineRenderer[])(object)new LineRenderer[4];
			for (int j = 0; j < 4; j++)
			{
				sparks[j] = UivoVisual.Line(((Component)this).transform, "FilamentoVioleta", 7);
				sparks[j].useWorldSpace = true;
				sparks[j].widthMultiplier = 0.012f;
			}
			UivoVisual.BuffAuras.Add(this);
			Sample(0f);
		}

		internal void Sample(float time)
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)chest == (Object)null || (Object)(object)head == (Object)null)
			{
				return;
			}
			Vector3 position = chest.position;
			((Component)wisps[0]).transform.position = position;
			((Component)wisps[1]).transform.position = head.position + Vector3.up * 0.1f;
			((Component)wisps[2]).transform.position = (((Object)(object)left != (Object)null) ? left.position : position);
			((Component)wisps[3]).transform.position = (((Object)(object)right != (Object)null) ? right.position : position);
			for (int i = 0; i < sparks.Length; i++)
			{
				for (int j = 0; j < 7; j++)
				{
					float num = (float)j / 6f;
					float num2 = time * 1.8f + (float)i * (float)Math.PI * 0.5f + num * 1.9f;
					float num3 = 0.23f + 0.015f * Mathf.Sin(time * 27f + (float)(j * 5) + (float)i);
					sparks[i].SetPosition(j, position + new Vector3(Mathf.Cos(num2) * num3, (num - 0.5f) * 0.42f, Mathf.Sin(num2) * num3));
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)source == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			bool flag = UivoVisual.Paused?.Invoke() ?? false;
			if (flag != paused)
			{
				ParticleSystem[] array = wisps;
				foreach (ParticleSystem val in array)
				{
					if (flag)
					{
						val.Pause();
					}
					else
					{
						val.Play();
					}
				}
				paused = flag;
			}
			if (!flag)
			{
				age += Time.deltaTime;
				Sample(age);
			}
		}

		private void OnDestroy()
		{
			UivoVisual.BuffAuras.Remove(this);
		}
	}
}

BepInEx/plugins/Codex_Vale_Prismatico/CodexValePrismatico.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using CodexCidadePostes;
using CodexColossoFloresta;
using CodexCombat;
using CodexFendaHostil;
using CodexGolemExterno;
using CodexLoboGelo;
using CodexLobosElementais;
using CodexValePrismatico;
using Microsoft.CodeAnalysis;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodexCombat
{
	internal static class PhysicalContactHit
	{
		internal static bool CanBlock(bool blockable, bool blocking, bool hasWeapon, float angle, float blockAngle)
		{
			if (blockable && blocking && hasWeapon)
			{
				return angle < blockAngle;
			}
			return false;
		}

		internal static bool Apply(MonoBehaviour source, Character dealer, Character target, float damage, Vector3 direction, float impact, bool blockable)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)source).transform.position - ((Component)target).transform.position;
			float num = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? Vector3.Angle(((Component)target).transform.forward, val) : 180f);
			Weapon val2 = (target.ShieldEquipped ? target.LeftHandWeapon : target.CurrentWeapon);
			float blockAngle = (target.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE);
			DamageList val3 = new DamageList((Types)0, damage);
			if (!CanBlock(blockable, target.Blocking, (Object)(object)val2 != (Object)null, num, blockAngle))
			{
				target.ReceiveHit((Object)null, val3, direction, target.CenterPosition, 45f, 1f, dealer, impact, true);
				return false;
			}
			float num2 = UnityEngineExtensions.AngleDir(direction, ((Component)target).transform.forward, Vector3.up);
			if ((Object)(object)target.CurrentWeapon != (Object)null && (int)target.CurrentWeapon.Type == 55)
			{
				target.Stats.GetMitigatedDamage((Tag[])null, ref val3, false);
				float num3 = val3.TotalDamage * 0.1f;
				AnimationCurve deathImpulseCurve = CharacterManager.Instance.DeathImpulseCurve;
				Vector3 val4 = direction * Mathf.Clamp(deathImpulseCurve.Evaluate(Mathf.Clamp(num3, 0f, 200f)) + deathImpulseCurve.Evaluate(Mathf.Clamp(impact, 0f, 200f)), 0f, 60f);
				target.VitalityHit(dealer, num3, val4);
			}
			target.ReceiveBlock(source, damage, direction, num, num2, dealer, impact);
			return true;
		}
	}
}
namespace CodexValePrismatico
{
	internal struct Vertex
	{
		internal float X;

		internal float Y;

		internal float Z;

		internal float U;

		internal float V;

		internal Vertex(float x, float y, float z, float u, float v)
		{
			X = x;
			Y = y;
			Z = z;
			U = u;
			V = v;
		}
	}
	internal sealed class CrystalData
	{
		internal readonly List<Vertex> Vertices = new List<Vertex>();

		internal readonly List<int> Triangles = new List<int>();
	}
	internal static class CrystalGeometry
	{
		internal static CrystalData Build()
		{
			CrystalData crystalData = new CrystalData();
			List<Vertex> vertices = crystalData.Vertices;
			List<int> triangles = crystalData.Triangles;
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 7; j++)
				{
					double num = (double)j * Math.PI * 2.0 / 7.0;
					float num2 = i switch
					{
						1 => 1f, 
						0 => 0.72f, 
						_ => 0.65f, 
					} * (1f + 0.14f * (float)Math.Sin((double)j * 5.71));
					vertices.Add(new Vertex((float)Math.Cos(num) * num2 + ((i == 2) ? 0.12f : 0f), i switch
					{
						1 => 0.57f, 
						0 => 0f, 
						_ => 0.88f, 
					}, (float)Math.Sin(num) * num2, (float)j / 7f, (float)i / 2f));
				}
			}
			for (int k = 0; k < 2; k++)
			{
				for (int l = 0; l < 7; l++)
				{
					int num3 = k * 7 + l;
					int num4 = k * 7 + (l + 1) % 7;
					int item = num3 + 7;
					int item2 = num4 + 7;
					triangles.Add(num3);
					triangles.Add(item);
					triangles.Add(num4);
					triangles.Add(num4);
					triangles.Add(item);
					triangles.Add(item2);
				}
			}
			int count = vertices.Count;
			vertices.Add(new Vertex(0.23f, 1f, 0f, 0.5f, 1f));
			int count2 = vertices.Count;
			vertices.Add(new Vertex(0f, 0f, 0f, 0f, 0f));
			for (int m = 0; m < 7; m++)
			{
				int num5 = (m + 1) % 7;
				triangles.Add(14 + m);
				triangles.Add(count);
				triangles.Add(14 + num5);
				triangles.Add(m);
				triangles.Add(num5);
				triangles.Add(count2);
			}
			return crystalData;
		}
	}
	internal sealed class EnvironmentBuilder : MonoBehaviour
	{
		private sealed class Lamp
		{
			internal Light Light;

			internal bool Mineral;

			internal float Distance;
		}

		private readonly List<Object> _owned = new List<Object>();

		private readonly List<Lamp> _lights = new List<Lamp>();

		private readonly Dictionary<string, Material> _skins = new Dictionary<string, Material>();

		private readonly Dictionary<string, Mesh> _meshes = new Dictionary<string, Mesh>();

		private readonly Dictionary<string, Texture2D> _textures = new Dictionary<string, Texture2D>();

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

		private readonly List<ParticleSystem> _particles = new List<ParticleSystem>();

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

		private readonly List<Vector2> _roadUV = new List<Vector2>();

		private readonly List<int> _roadTriangles = new List<int>();

		private WorldGround _ground;

		private StreetResources _street;

		private Material _rock;

		private Material _bark;

		private Material _crystal;

		private Material _road;

		private Material _terrain;

		private Material _dust;

		private float _night;

		private int _roadSegments;

		private int _posts;

		private int _props;

		private string _assets;

		internal string Summary => "32 lotes organicos/" + _props + " objetos;" + _roadSegments + " trechos de estrada/" + _posts + " postes;MAX8 luzes proximas;6 emissores/144 particulas";

		internal void Initialize(WorldGround ground)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Expected O, but got Unknown
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			_ground = ground;
			_assets = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "Assets");
			_rock = Material(new Color(0.44f, 0.46f, 0.5f), "Pedra_Mineral", (Texture)(object)Texture("rocky_terrain_diff_1k.jpg"));
			_bark = Material(new Color(0.7f, 0.68f, 0.73f), "Casca_Organica", (Texture)(object)Texture("bark_diffuse.png"));
			_crystal = Material(new Color(0.31f, 0.68f, 0.73f), "Prisma_Mineral", (Texture)(object)Texture("rocky_terrain_diff_1k.jpg"));
			_crystal.SetFloat("_Glossiness", 0.45f);
			_crystal.EnableKeyword("_EMISSION");
			_crystal.SetColor("_EmissionColor", new Color(0.04f, 0.12f, 0.15f));
			_road = Material(new Color(0.65f, 0.62f, 0.54f), "Estrada_Cascalho_1K", (Texture)(object)Texture("mud_cracked_dry_03_diff_1k.jpg"));
			_terrain = Material(Color.white, "Vale_Estratos_1K", (Texture)(object)TerrainTexture());
			_terrain.SetFloat("_Mode", 1f);
			_terrain.SetFloat("_Cutoff", 0.5f);
			_terrain.EnableKeyword("_ALPHATEST_ON");
			_terrain.renderQueue = 2450;
			_terrain.SetTexture("_DetailAlbedoMap", (Texture)(object)GrainTexture());
			_terrain.SetFloat("_UVSec", 1f);
			_terrain.EnableKeyword("_DETAIL_MULX2");
			_terrain.SetTexture("_DetailNormalMap", (Texture)(object)Normal("rocky_terrain_nor_gl_1k.jpg"));
			_terrain.SetFloat("_DetailNormalMapScale", 0.45f);
			SetNormal(_rock, "rocky_terrain_nor_gl_1k.jpg", 0.55f);
			SetNormal(_crystal, "rocky_terrain_nor_gl_1k.jpg", 0.2f);
			SetNormal(_road, "mud_cracked_dry_03_nor_gl_1k.jpg", 0.45f);
			SetNormal(_bark, "bark_normal.png", 0.6f);
			_street = ((Component)this).gameObject.AddComponent<StreetResources>();
			_street.Load();
			Texture2D val = Own<Texture2D>(new Texture2D(64, 64, (TextureFormat)4, false));
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j - 31.5f) / 31.5f;
					float num2 = ((float)i - 31.5f) / 31.5f;
					float num3 = num * num + num2 * num2;
					array[i * 64 + j] = new Color(0.58f, 0.9f, 1f, Mathf.Pow(Mathf.Clamp01(1f - num3), 3f));
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			_dust = Own<Material>(new Material(Shader.Find("Sprites/Default")));
			_dust.mainTexture = (Texture)(object)val;
		}

		internal IEnumerable<object> Build()
		{
			foreach (object item in BuildTerrain())
			{
				yield return item;
			}
			foreach (object item2 in BuildRoads())
			{
				yield return item2;
			}
			BuildNature();
			BuildArena();
			_renderers.AddRange(((Component)this).GetComponentsInChildren<Renderer>(true));
			Physics.SyncTransforms();
			Tick();
		}

		private IEnumerable<object> BuildTerrain()
		{
			for (float x = -2210f; x < -1890f; x += 40f)
			{
				List<Vector3> list = new List<Vector3>();
				List<Vector2> list2 = new List<Vector2>();
				List<Vector2> list3 = new List<Vector2>();
				List<int> list4 = new List<int>();
				int num = (int)Mathf.Min(8f, (-1890f - x) / 5f);
				int num2 = 84;
				for (int i = 0; i <= num2; i++)
				{
					for (int j = 0; j <= num; j++)
					{
						Point p = new Point(x + (float)(j * 5), -210f + (float)(i * 5));
						if (!_ground.Sample(p, out var surface, out var _))
						{
							float x2 = p.X;
							string text = x2.ToString();
							x2 = p.Z;
							throw new InvalidOperationException("Incomplete existing floor at " + text + "," + x2);
						}
						list.Add(surface + Vector3.up * 0.015f);
						list2.Add(new Vector2((p.X - -2210f) / 320f, (p.Z - -210f) / 420f));
						list3.Add(new Vector2(p.X, p.Z) / 4f);
					}
				}
				for (int k = 0; k < num2; k++)
				{
					for (int l = 0; l < num; l++)
					{
						int num3 = k * (num + 1) + l;
						int item = num3 + 1;
						int num4 = num3 + num + 1;
						int item2 = num4 + 1;
						list4.Add(item);
						list4.Add(num3);
						list4.Add(num4);
						list4.Add(item);
						list4.Add(num4);
						list4.Add(item2);
					}
				}
				Mesh val = Own<Mesh>(new Mesh
				{
					name = "Vale_Superficie_Visual_" + x
				});
				val.SetVertices(list);
				val.SetUVs(0, list2);
				val.SetUVs(1, list3);
				val.SetTriangles(list4, 0);
				val.RecalculateNormals();
				val.RecalculateTangents();
				val.RecalculateBounds();
				MeshObject("Vale_Superficie_Visual_" + x, val, _terrain, Vector3.zero, Quaternion.identity, Vector3.one, solid: false, 0);
				yield return null;
			}
		}

		private IEnumerable<object> BuildRoads()
		{
			_ground.CacheFaces();
			int index = 0;
			Point[][] roads = RegionPlan.Roads;
			foreach (Point[] road in roads)
			{
				float postDistance = 0f;
				int side = 1;
				for (int s = 1; s < road.Length; s++)
				{
					Point a = road[s - 1];
					Point b = road[s];
					float length = RegionPlan.Distance(a, b);
					int count = Mathf.CeilToInt(length / 2.5f);
					Vector3 val = new Vector3(b.X - a.X, 0f, b.Z - a.Z);
					Vector3 forward = ((Vector3)(ref val)).normalized;
					Vector3 across = new Vector3(0f - forward.z, 0f, forward.x);
					for (int j = 0; j < count; j++)
					{
						float num = (float)j / (float)count;
						float num2 = (float)(j + 1) / (float)count;
						Point a2 = new Point(Mathf.Lerp(a.X, b.X, num), Mathf.Lerp(a.Z, b.Z, num));
						RoadPiece(b: new Point(Mathf.Lerp(a.X, b.X, num2), Mathf.Lerp(a.Z, b.Z, num2)), a: a2, across: across, id: index++);
						postDistance += length / (float)count;
						if (postDistance >= 34f)
						{
							postDistance = 0f;
							TryPost(new Point(a2.X + across.x * 6f * (float)side, a2.Z + across.z * 6f * (float)side), forward);
							side = -side;
						}
						if (index % 32 == 0)
						{
							FlushRoad(index);
							yield return null;
						}
					}
				}
				FlushRoad(index);
			}
		}

		private void RoadPiece(Point a, Point b, Vector3 across, int id)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Vector3 val3 = default(Vector3);
			foreach (WorldGround.Face item in _ground.Faces(a, b, 4.6f))
			{
				List<SurfacePoint> list = RoadGeometry.Clip(item.A, item.B, item.C, a, b, 4.6f);
				if (list.Count < 3)
				{
					continue;
				}
				float num = 0f;
				float num2 = 0f;
				float num3 = 0f;
				foreach (SurfacePoint item2 in list)
				{
					num += item2.X;
					num2 += item2.Y;
					num3 += item2.Z;
				}
				num /= (float)list.Count;
				num2 /= (float)list.Count;
				num3 /= (float)list.Count;
				if (!_ground.Sample(new Point(num, num3), out var surface, out var floor) || Mathf.Abs(surface.y - WorldGround.Origin.y - num2) > 0.008f || (Object)(object)floor != (Object)(object)item.Floor)
				{
					continue;
				}
				bool flag2 = false;
				Collider[] array = Physics.OverlapSphere(surface + Vector3.up * 0.45f, 0.34f, Global.GeneralEnvironmentMask, (QueryTriggerInteraction)1);
				foreach (Collider val in array)
				{
					if (!WorldGround.IsFloor(val))
					{
						Bounds bounds = val.bounds;
						if (((Bounds)(ref bounds)).max.y > surface.y + 0.15f)
						{
							flag2 = true;
							break;
						}
					}
				}
				if (flag2)
				{
					continue;
				}
				for (int j = 1; j < list.Count - 1; j++)
				{
					SurfacePoint surfacePoint = list[0];
					SurfacePoint surfacePoint2 = list[j];
					SurfacePoint surfacePoint3 = list[j + 1];
					Vector3 val2 = new Vector3(surfacePoint2.X - surfacePoint.X, surfacePoint2.Y - surfacePoint.Y, surfacePoint2.Z - surfacePoint.Z);
					((Vector3)(ref val3))..ctor(surfacePoint3.X - surfacePoint.X, surfacePoint3.Y - surfacePoint.Y, surfacePoint3.Z - surfacePoint.Z);
					Vector3 val4 = Vector3.Cross(val2, val3);
					if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-08f))
					{
						SurfacePoint[] array2 = new SurfacePoint[3] { surfacePoint, surfacePoint2, surfacePoint3 };
						for (int i = 0; i < array2.Length; i++)
						{
							SurfacePoint surfacePoint4 = array2[i];
							float num4 = (RegionPlan.InRegion(surfacePoint4.X, surfacePoint4.Z) ? 0.04f : 0.02f);
							_roadTriangles.Add(_roadVertices.Count);
							_roadVertices.Add(WorldGround.Origin + new Vector3(surfacePoint4.X, surfacePoint4.Y + num4, surfacePoint4.Z));
							_roadUV.Add(new Vector2(surfacePoint4.X / 3f, surfacePoint4.Z / 3f));
						}
						flag = true;
					}
				}
			}
			if (flag)
			{
				_roadSegments++;
			}
		}

		private void FlushRoad(int id)
		{
			//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_0030: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (_roadVertices.Count != 0)
			{
				Mesh val = Own<Mesh>(new Mesh
				{
					name = "Estrada_Lote_" + id
				});
				val.SetVertices(_roadVertices);
				val.SetUVs(0, _roadUV);
				val.SetTriangles(_roadTriangles, 0);
				val.RecalculateNormals();
				val.RecalculateBounds();
				MeshObject("Estrada_Lote_" + id, val, _road, Vector3.zero, Quaternion.identity, Vector3.one, solid: false, 0);
				_roadVertices.Clear();
				_roadUV.Clear();
				_roadTriangles.Clear();
			}
		}

		private void TryPost(Point point, Vector3 forward)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (RegionPlan.RoadPostAllowed(point) && _ground.Free(point, 1.2f, 4.2f, out var surface, out var floor))
			{
				GameObject val = new GameObject("Estrada_Poste_" + _posts);
				val.transform.SetParent(((Component)this).transform, true);
				val.transform.position = surface;
				val.transform.rotation = Quaternion.LookRotation(forward);
				val.layer = ((Component)floor).gameObject.layer;
				_street.Part(val, "Ferro_Torneado", _street.Stand, _street.Iron);
				_street.Part(val, "Lanterna_CC0", _street.Lantern, _street.Lamp, solid: true);
				Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				CapsuleCollider obj = val.AddComponent<CapsuleCollider>();
				obj.radius = 0.3f;
				obj.height = 3.8f;
				obj.center = new Vector3(0f, 1.82f, 0.08f);
				AddLight(val.transform, surface + val.transform.rotation * new Vector3(0f, 3.35f, -0.65f), mineral: false);
				_posts++;
			}
		}

		private void BuildNature()
		{
			//IL_008a: 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)
			int num = 0;
			Point[] array = RegionPlan.NatureSites();
			for (int i = 0; i < array.Length; i++)
			{
				Point hint = array[i];
				if (!_ground.Free(hint, 1.5f, 7f, out var surface, out var floor))
				{
					num++;
					continue;
				}
				bool flag = num % 4 == 0;
				float size = (flag ? (6.5f + (float)(num % 3)) : (3.5f + (float)(num % 5) * 0.6f));
				PlaceModel(flag ? "gnarled_tree" : ("boulder_" + (num % 3 + 1)), surface, size, num * 137, flag ? _bark : _rock, ((Component)floor).gameObject.layer);
				if (!flag && num % 2 == 0)
				{
					Point p = new Point(hint.X + 2.6f, hint.Z - 1.2f);
					if (_ground.Sample(p, out var surface2, out var floor2))
					{
						Crystal(surface2, 2.8f + (float)(num % 4), 137 * num, ((Component)floor2).gameObject.layer, num % 6 == 0);
					}
				}
				num++;
			}
		}

		private void BuildArena()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 24; i++)
			{
				if (i % 6 != 0 && i % 6 != 1)
				{
					float num = (float)i * (float)Math.PI * 2f / 24f;
					Point p = new Point(-2050f + Mathf.Cos(num) * 39f, Mathf.Sin(num) * 39f);
					if (_ground.Sample(p, out var surface, out var floor))
					{
						PlaceModel("boulder_" + (i % 3 + 1), surface, 7.5f + (float)(i % 4), i * 41, _rock, ((Component)floor).gameObject.layer);
					}
				}
			}
			int[] array = new int[2] { -1, 1 };
			foreach (int num2 in array)
			{
				Point p2 = new Point(-2050f + (float)(num2 * 44), 22f);
				if (_ground.Sample(p2, out var surface2, out var floor2))
				{
					Crystal(surface2, 9f, num2 * 38, ((Component)floor2).gameObject.layer, lit: true);
				}
			}
			for (int k = 0; k < 6; k++)
			{
				float num3 = ((float)k + 0.5f) * (float)Math.PI * 2f / 6f;
				Point p3 = new Point(-2050f + Mathf.Cos(num3) * 29f, Mathf.Sin(num3) * 29f);
				if (_ground.Sample(p3, out var surface3, out var floor3))
				{
					Crystal(surface3, 1.4f, k * 53, ((Component)floor3).gameObject.layer, lit: false);
					Dust(surface3 + Vector3.up * 1.4f);
					if (k % 2 == 0)
					{
						AddLight(((Component)this).transform, surface3 + Vector3.up * 2f, mineral: true);
					}
				}
			}
		}

		private void PlaceModel(string name, Vector3 ground, float size, float yaw, Material material, int layer)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			if (!_meshes.TryGetValue(name, out var value))
			{
				value = ReadObj(Path.Combine(_assets, name + ".obj"));
				_meshes[name] = value;
			}
			Bounds bounds;
			float num;
			if (!(name == "gnarled_tree"))
			{
				bounds = value.bounds;
				float x = ((Bounds)(ref bounds)).size.x;
				bounds = value.bounds;
				float y = ((Bounds)(ref bounds)).size.y;
				bounds = value.bounds;
				num = Mathf.Max(x, Mathf.Max(y, ((Bounds)(ref bounds)).size.z));
			}
			else
			{
				bounds = value.bounds;
				num = ((Bounds)(ref bounds)).size.y;
			}
			float num2 = num;
			float num3 = size / num2;
			Quaternion val = Quaternion.Euler(0f, yaw, 0f);
			if (name != "gnarled_tree")
			{
				float num4 = ground.y;
				for (int i = -1; i <= 1; i++)
				{
					for (int j = -1; j <= 1; j++)
					{
						float num5 = i;
						bounds = value.bounds;
						float num6 = num5 * ((Bounds)(ref bounds)).extents.x * num3;
						float num7 = j;
						bounds = value.bounds;
						Vector3 val2 = val * new Vector3(num6, 0f, num7 * ((Bounds)(ref bounds)).extents.z * num3);
						if (!_ground.Sample(new Point(ground.x - WorldGround.Origin.x + val2.x, ground.z - WorldGround.Origin.z + val2.z), out var surface, out var _))
						{
							return;
						}
						num4 = Mathf.Min(num4, surface.y);
					}
				}
				ground.y = num4;
			}
			bounds = value.bounds;
			float num8 = 0f - ((Bounds)(ref bounds)).center.x;
			bounds = value.bounds;
			float num9 = 0f - ((Bounds)(ref bounds)).min.y;
			bounds = value.bounds;
			Vector3 val3 = new Vector3(num8, num9, 0f - ((Bounds)(ref bounds)).center.z) * num3;
			GameObject val4 = MeshObject("Vale_" + name + "_" + _props, value, material, ground + val * val3 - Vector3.up * 0.13f, val, Vector3.one * num3, solid: true, layer);
			if (name == "gnarled_tree")
			{
				Object.Destroy((Object)(object)val4.GetComponent<MeshCollider>());
				CapsuleCollider val5 = val4.AddComponent<CapsuleCollider>();
				val5.radius = 0.23f / num3;
				val5.height = size * 0.65f / num3;
				bounds = value.bounds;
				float x2 = ((Bounds)(ref bounds)).center.x;
				bounds = value.bounds;
				float num10 = ((Bounds)(ref bounds)).min.y + val5.height / 2f;
				bounds = value.bounds;
				val5.center = new Vector3(x2, num10, ((Bounds)(ref bounds)).center.z);
			}
			_props++;
		}

		private void Crystal(Vector3 floor, float height, float yaw, int layer, bool lit)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Mesh mesh = CrystalMesh();
			Quaternion rotation = Quaternion.Euler(0f, yaw, -8f + yaw % 17f);
			GameObject val = MeshObject("Vale_Cristal_" + _props, mesh, _crystal, floor - Vector3.up * 0.18f, rotation, new Vector3(height * 0.32f, height, height * 0.27f), solid: true, layer);
			_props++;
			if (lit)
			{
				AddLight(val.transform, floor + Vector3.up * height * 0.6f, mineral: true);
			}
		}

		private Mesh CrystalMesh()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			if (_meshes.TryGetValue("crystal", out var value))
			{
				return value;
			}
			CrystalData crystalData = CrystalGeometry.Build();
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			foreach (Vertex vertex in crystalData.Vertices)
			{
				list.Add(new Vector3(vertex.X, vertex.Y, vertex.Z));
				list2.Add(new Vector2(vertex.U, vertex.V));
			}
			Mesh val = Own<Mesh>(new Mesh
			{
				name = "Prisma_Fechado_7Facetas"
			});
			val.SetVertices(list);
			val.SetUVs(0, list2);
			val.SetTriangles(crystalData.Triangles, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			_meshes["crystal"] = val;
			return val;
		}

		private void Dust(Vector3 point)
		{
			//IL_0005: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Vale_Poeira_Prismatica");
			val.transform.SetParent(((Component)this).transform, true);
			val.transform.position = point;
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).maxParticles = 24;
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(4f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.12f);
			((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.07f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.6f, 0.88f, 1f, 0.55f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(4f);
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 2f;
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[3]
			{
				new Keyframe(0f, 0f),
				new Keyframe(0.25f, 1f),
				new Keyframe(1f, 0f)
			}));
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = _dust;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			_particles.Add(val2);
		}

		private void AddLight(Transform parent, Vector3 point, bool mineral)
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(mineral ? "Luz_Mineral" : "Luz_Estrada");
			val.transform.SetParent(parent, true);
			val.transform.position = point;
			Light val2 = val.AddComponent<Light>();
			val2.type = (LightType)2;
			val2.color = (mineral ? new Color(0.45f, 0.8f, 1f) : new Color(1f, 0.8f, 0.52f));
			val2.range = (mineral ? 24 : 36);
			val2.intensity = (mineral ? 2.5f : 3.6f);
			val2.shadows = (LightShadows)0;
			val2.renderMode = (LightRenderMode)1;
			((Behaviour)val2).enabled = false;
			_lights.Add(new Lamp
			{
				Light = val2,
				Mineral = mineral
			});
		}

		internal void Tick()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			TOD_Sky instance = TOD_Sky.Instance;
			bool flag = (Object)(object)instance != (Object)null && instance.Initialized && instance.IsNight;
			_night = Mathf.MoveTowards(_night, (float)(flag ? 1 : 0), 0.125f);
			_street.SetNight(_night);
			foreach (Lamp light in _lights)
			{
				Character val = Plugin.NearestPlayer(((Component)light.Light).transform.position, 105f);
				float distance;
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = ((Component)val).transform.position - ((Component)light.Light).transform.position;
					distance = ((Vector3)(ref val2)).sqrMagnitude;
				}
				else
				{
					distance = float.MaxValue;
				}
				light.Distance = distance;
				((Behaviour)light.Light).enabled = false;
			}
			_lights.Sort((Lamp a, Lamp b) => a.Distance.CompareTo(b.Distance));
			int num = 0;
			foreach (Lamp light2 in _lights)
			{
				if (light2.Distance != float.MaxValue && num < 8)
				{
					float num2 = (light2.Mineral ? Mathf.Lerp(0.2f, 1f, _night) : _night);
					if (!(num2 < 0.001f))
					{
						light2.Light.intensity = (light2.Mineral ? 2.5f : 3.6f) * num2;
						((Behaviour)light2.Light).enabled = true;
						num++;
					}
				}
			}
			foreach (Renderer renderer in _renderers)
			{
				if (!((Object)(object)renderer == (Object)null) && !(renderer is ParticleSystemRenderer))
				{
					Bounds bounds = renderer.bounds;
					renderer.enabled = (Object)(object)Plugin.NearestPlayer(((Bounds)(ref bounds)).center, 300f) != (Object)null;
				}
			}
			foreach (ParticleSystem particle in _particles)
			{
				bool flag2 = (Object)(object)Plugin.NearestPlayer(((Component)particle).transform.position, 160f) != (Object)null;
				if (flag2 && !particle.isPlaying)
				{
					particle.Play();
				}
				else if (!flag2 && particle.isPlaying)
				{
					particle.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
		}

		internal void Paint(GameObject actor, Kind kind)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = actor.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is ParticleSystemRenderer)
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				Material[] array = (Material[])(object)new Material[sharedMaterials.Length];
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					string key = kind.ToString() + ":" + ((Object)val2).GetInstanceID();
					if (!_skins.TryGetValue(key, out var value))
					{
						value = Own<Material>(new Material(val2));
						((Object)value).name = "Vale_" + kind.ToString() + "_" + ((Object)val2).name;
						Texture mainTexture = val2.mainTexture;
						if ((Object)(object)mainTexture != (Object)null)
						{
							value.mainTexture = (Texture)(object)SkinTexture(mainTexture, kind);
						}
						value.color = Color.white;
						_skins[key] = value;
					}
					array[j] = value;
				}
				val.sharedMaterials = array;
			}
		}

		private Texture2D SkinTexture(Texture source, Kind kind)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0063: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: 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)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Min(1024, source.width);
			int num2 = Mathf.Min(1024, source.height);
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				Graphics.Blit(source, temporary);
				RenderTexture.active = temporary;
				val = Own<Texture2D>(new Texture2D(num, num2, (TextureFormat)4, true));
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
			Color[] pixels = val.GetPixels();
			Color val2 = (Color)(kind switch
			{
				Kind.Tide => new Color(0.055f, 0.18f, 0.2f), 
				Kind.Ember => new Color(0.22f, 0.07f, 0.035f), 
				Kind.Stone => new Color(0.17f, 0.13f, 0.25f), 
				_ => new Color(0.12f, 0.14f, 0.19f), 
			});
			Color val3 = (Color)(kind switch
			{
				Kind.Tide => new Color(0.58f, 0.87f, 0.85f), 
				Kind.Ember => new Color(0.95f, 0.51f, 0.22f), 
				Kind.Stone => new Color(0.71f, 0.61f, 0.79f), 
				_ => new Color(0.8f, 0.79f, 0.64f), 
			});
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < num; j++)
				{
					int num3 = i * num + j;
					Color val4 = pixels[num3];
					float num4 = Mathf.Clamp01(((Color)(ref val4)).grayscale * 1.3f);
					float num5 = Mathf.PerlinNoise((float)j / 52f + (float)(kind.GetHashCode() * 7), (float)i / 73f + 19f);
					Color val5 = Color.Lerp(val2, val3, Mathf.Clamp01((num5 - 0.3f) * 2.5f));
					val5 *= Mathf.Lerp(0.4f, 1.25f, num4);
					if (kind == Kind.Regent && Mathf.Abs(Mathf.Sin((float)j * 0.12f + (float)i * 0.07f + num5 * 8f)) < 0.055f)
					{
						val5 = Color.Lerp(val5, new Color(0.3f, 0.83f, 0.87f), 0.8f);
					}
					val5.a = val4.a;
					pixels[num3] = val5;
				}
			}
			((Object)val).name = "Vale_Mescla_" + kind;
			val.SetPixels(pixels);
			val.Apply(true, true);
			((Texture)val).filterMode = (FilterMode)2;
			return val;
		}

		private Texture2D TerrainTexture()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = Own<Texture2D>(new Texture2D(1024, 1024, (TextureFormat)4, true));
			Color[] array = (Color[])(object)new Color[1048576];
			for (int i = 0; i < 1024; i++)
			{
				for (int j = 0; j < 1024; j++)
				{
					float num = -2210f + (float)j / 1023f * 320f;
					float num2 = -210f + (float)i / 1023f * 420f;
					float num3 = Mathf.PerlinNoise(num / 55f + 47f, num2 / 67f + 83f);
					float num4 = Mathf.PerlinNoise(num * 1.7f + 3f, num2 * 1.7f + 17f);
					Color val2 = Color.Lerp(new Color(0.38f, 0.48f, 0.47f), new Color(0.62f, 0.6f, 0.7f), Mathf.SmoothStep(0f, 1f, num3));
					float num5 = Mathf.PerlinNoise(num / 18f + 2f, num2 / 28f + 9f);
					val2 = Color.Lerp(val2, new Color(0.76f, 0.73f, 0.63f), Mathf.Clamp01((num5 - 0.4f) * 1.8f));
					float num6 = Mathf.Sqrt((num - -2050f) * (num - -2050f) + num2 * num2);
					if (num6 < 34f)
					{
						val2 = Color.Lerp(val2, new Color(0.37f, 0.41f, 0.43f), 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(26f, 34f, num6)));
					}
					val2 *= Mathf.Lerp(0.86f, 1.1f, num4);
					float num7 = Mathf.Min(num - -2210f, Mathf.Min(-1890f - num, Mathf.Min(num2 - -210f, 210f - num2)));
					val2.a = ((num7 > 8f + 9f * Mathf.PerlinNoise(num / 24f + 61f, num2 / 28f + 74f)) ? 1 : 0);
					array[i * 1024 + j] = val2;
				}
			}
			val.SetPixels(array);
			val.Apply(true, true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)2;
			return val;
		}

		private Texture2D GrainTexture()
		{
			//IL_004f: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			Texture2D val = Texture("rocky_terrain_diff_1k.jpg");
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				float num = Mathf.Clamp(0.5f + (((Color)(ref pixels[i])).grayscale - 0.5f) * 0.7f, 0.25f, 0.75f);
				pixels[i] = new Color(num, num, num, 1f);
			}
			Texture2D obj = Own<Texture2D>(new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)3, true));
			obj.SetPixels(pixels);
			obj.Apply(true, true);
			((Texture)obj).filterMode = (FilterMode)2;
			return obj;
		}

		private Texture2D Texture(string file)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (_textures.TryGetValue(file, out var value))
			{
				return value;
			}
			Texture2D val = Own<Texture2D>(new Texture2D(2, 2, (TextureFormat)4, true));
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(_assets, file)), false) || ((Texture)val).width > 1024 || ((Texture)val).height > 1024)
			{
				throw new InvalidDataException("Invalid/oversized texture:" + file);
			}
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 2;
			_textures[file] = val;
			return val;
		}

		private Texture2D Normal(string file)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (_textures.TryGetValue("normal:" + file, out var value))
			{
				return value;
			}
			Texture2D val = Texture(file);
			Texture2D val2 = Own<Texture2D>(new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true, true));
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val3 = pixels[i];
				pixels[i] = new Color(val3.g, val3.g, val3.g, val3.r);
			}
			val2.SetPixels(pixels);
			val2.Apply(true, true);
			((Texture)val2).filterMode = (FilterMode)2;
			_textures["normal:" + file] = val2;
			return val2;
		}

		private void SetNormal(Material material, string file, float strength)
		{
			material.SetTexture("_BumpMap", (Texture)(object)Normal(file));
			material.SetFloat("_BumpScale", strength);
			material.EnableKeyword("_NORMALMAP");
		}

		private Material Material(Color color, string name, Texture texture)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Native Standard shader missing");
			}
			Material obj = Own<Material>(new Material(val));
			((Object)obj).name = name;
			obj.color = color;
			obj.mainTexture = texture;
			obj.SetFloat("_Glossiness", 0.1f);
			return obj;
		}

		private GameObject MeshObject(string name, Mesh mesh, Material material, Vector3 position, Quaternion rotation, Vector3 scale, bool solid, int layer)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, true);
			val.transform.position = position;
			val.transform.rotation = rotation;
			val.transform.localScale = scale;
			val.layer = layer;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).enabled = false;
			if (solid)
			{
				val.AddComponent<MeshCollider>().sharedMesh = mesh;
			}
			return val;
		}

		private Mesh ReadObj(string path)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<Vector3> list4 = new List<Vector3>();
			List<Vector2> list5 = new List<Vector2>();
			List<Vector3> list6 = new List<Vector3>();
			List<int> list7 = new List<int>();
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			bool flag = true;
			foreach (string item in File.ReadLines(path))
			{
				string text = item.Trim();
				if (text.Length == 0 || text[0] == '#')
				{
					continue;
				}
				string[] array = text.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
				if (array[0] == "v")
				{
					list.Add(new Vector3(Number(array[1]), Number(array[2]), 0f - Number(array[3])));
				}
				else if (array[0] == "vt")
				{
					list3.Add(new Vector2(Number(array[1]), Number(array[2])));
				}
				else if (array[0] == "vn")
				{
					list2.Add(new Vector3(Number(array[1]), Number(array[2]), 0f - Number(array[3])));
				}
				else
				{
					if (!(array[0] == "f"))
					{
						continue;
					}
					List<int> list8 = new List<int>();
					for (int i = 1; i < array.Length && !array[i].StartsWith("#"); i++)
					{
						if (!dictionary.TryGetValue(array[i], out var value))
						{
							string[] array2 = array[i].Split(new char[1] { '/' });
							value = list4.Count;
							list4.Add(list[Index(array2[0], list.Count)]);
							list5.Add((array2.Length > 1 && array2[1].Length > 0) ? list3[Index(array2[1], list3.Count)] : Vector2.zero);
							bool flag2 = array2.Length > 2 && array2[2].Length > 0;
							list6.Add(flag2 ? list2[Index(array2[2], list2.Count)] : Vector3.up);
							flag = flag && flag2;
							dictionary[array[i]] = value;
						}
						list8.Add(value);
					}
					for (int j = 1; j < list8.Count - 1; j++)
					{
						list7.Add(list8[0]);
						list7.Add(list8[j + 1]);
						list7.Add(list8[j]);
					}
				}
			}
			if (list4.Count > 30000 || list7.Count == 0)
			{
				throw new InvalidDataException("Invalid lightweight OBJ:" + path);
			}
			Mesh val = Own<Mesh>(new Mesh
			{
				name = "Vale_Imported_" + Path.GetFileNameWithoutExtension(path)
			});
			val.SetVertices(list4);
			val.SetUVs(0, list5);
			val.SetTriangles(list7, 0);
			if (flag)
			{
				val.SetNormals(list6);
			}
			else
			{
				val.RecalculateNormals();
			}
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
		}

		private static float Number(string s)
		{
			return float.Parse(s, CultureInfo.InvariantCulture);
		}

		private static int Index(string s, int count)
		{
			int num = int.Parse(s, CultureInfo.InvariantCulture);
			num = ((num > 0) ? (num - 1) : (count + num));
			if (num < 0 || num >= count)
			{
				throw new InvalidDataException("OBJ index out of bounds");
			}
			return num;
		}

		private T Own<T>(T resource) where T : Object
		{
			_owned.Add((Object)(object)resource);
			return resource;
		}

		private void OnDestroy()
		{
			foreach (Lamp light in _lights)
			{
				if ((Object)(object)light.Light != (Object)null)
				{
					((Behaviour)light.Light).enabled = false;
				}
			}
			foreach (Object item in _owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			_owned.Clear();
		}
	}
	[BepInPlugin("codex.outward.vale.prismatico", "Codex - Vale Prismatico e Estradas", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Slot
		{
			internal Lot Lot;

			internal SL_Character Template;

			internal Character Body;

			internal GameObject Actor;

			internal bool Complete;

			internal float Retry;
		}

		internal static Plugin Instance;

		private readonly List<Slot> _slots = new List<Slot>();

		private readonly Dictionary<Kind, GameObject> _prefabs = new Dictionary<Kind, GameObject>();

		private readonly List<AssetBundle> _ownedBundles = new List<AssetBundle>();

		private static List<Character> _players = new List<Character>();

		private static float _playerScan = -1f;

		private readonly WorldGround _ground = new WorldGround();

		private EnvironmentBuilder _environment;

		private GameObject _root;

		private bool _building;

		private bool _creating;

		private int _generation;

		private float _scan;

		private float _retryBuild;

		private void Awake()
		{
			Instance = this;
			Lot[] lots = RegionPlan.Lots;
			foreach (Lot lot in lots)
			{
				_slots.Add(new Slot
				{
					Lot = lot
				});
			}
			SL.OnPacksLoaded += Prepare;
			SceneManager.sceneLoaded += SceneLoaded;
			if (SL.PacksLoaded)
			{
				Prepare();
			}
			Report("Inicio", "1.0.0;320x420m;9 guardioes/3variantes+Regente1400HP;estradas5ramos;cenario independente,pisos existentes preservados.");
		}

		private void Prepare()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0054: 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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			foreach (Slot slot in _slots)
			{
				if (slot.Template == null)
				{
					Lot lot = slot.Lot;
					SL_Character val = new SL_Character
					{
						UID = "codex.character.vale.prismatico.v1." + lot.Id,
						Name = lot.Name,
						SaveType = (CharSaveType)0,
						SceneToSpawn = "",
						DestroyOnDeath = false,
						StartingPose = (SpellCastType)(-1),
						Scale = Vector3.one,
						StartSheathed = true,
						Faction = (Factions)9,
						CharacterVisualsData = new VisualData(),
						Weapon_ID = -1,
						Shield_ID = -1,
						Helmet_ID = -1,
						Chest_ID = -1,
						Boots_ID = -1,
						Backpack_ID = -1,
						Health = lot.Health,
						HealthRegen = 0f,
						Protection = 0f,
						Barrier = 0f,
						ImpactResist = 100f,
						Damage_Resists = new float[9],
						LootableOnDeath = false,
						DropWeapons = false,
						DropPouchContents = false
					};
					((ContentTemplate)val).ApplyTemplate();
					slot.Template = val;
				}
			}
		}

		private static bool Playable()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "CierzoTutorial" && (Object)(object)CharacterManager.Instance != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
			{
				return !NetworkLevelLoader.Instance.IsGameplayPaused;
			}
			return false;
		}

		private void Update()
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			if (!Playable() || Time.realtimeSinceStartup < _scan)
			{
				return;
			}
			_scan = Time.realtimeSinceStartup + 0.5f;
			if ((Object)(object)_root == (Object)null && !_building && Time.realtimeSinceStartup >= _retryBuild)
			{
				_retryBuild = Time.realtimeSinceStartup + 10f;
				if (_ground.Refresh())
				{
					((MonoBehaviour)this).StartCoroutine(Build(_generation));
				}
				else
				{
					Report("Piso", "Aguardando cidade completa/64setores;nao cria piso substituto.");
				}
			}
			if ((Object)(object)_environment != (Object)null)
			{
				_environment.Tick();
			}
			if ((Object)(object)_root == (Object)null || _building || _creating || PhotonNetwork.isNonMasterClientInRoom)
			{
				return;
			}
			foreach (Slot slot in _slots)
			{
				Vector3 point = WorldGround.Origin + new Vector3(slot.Lot.Point.X, 0f, slot.Lot.Point.Z);
				if (slot.Template != null && !slot.Complete && !(Time.realtimeSinceStartup < slot.Retry) && !((Object)(object)NearestPlayer(point, 155f) == (Object)null))
				{
					float radius = ((slot.Lot.Kind == Kind.Regent) ? 1f : ((slot.Lot.Kind == Kind.Stone) ? 0.7f : 0.65f));
					float height = ((slot.Lot.Kind == Kind.Regent) ? 3.8f : ((slot.Lot.Kind == Kind.Stone) ? 2.65f : 1.4f));
					if (_ground.Free(slot.Lot.Point, radius, height, out var surface, out var _))
					{
						((MonoBehaviour)this).StartCoroutine(Create(slot, surface, _generation));
						break;
					}
					slot.Retry = Time.realtimeSinceStartup + 15f;
					Report(slot.Lot.Id, "AGUARDANDO lote livre/apoio real;sem teleport de locomocao.");
				}
			}
		}

		private IEnumerator Build(int generation)
		{
			_building = true;
			try
			{
				_root = new GameObject("Codex_Vale_Prismatico_Root");
				SceneManager.MoveGameObjectToScene(_root, SceneManager.GetActiveScene());
				_environment = _root.AddComponent<EnvironmentBuilder>();
				_environment.Initialize(_ground);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				Cleanup();
				yield break;
			}
			IEnumerator<object> steps = _environment.Build().GetEnumerator();
			bool failed = false;
			while (generation == _generation)
			{
				bool flag;
				try
				{
					flag = steps.MoveNext();
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("[ValePrisma] Cenario isolado falhou:" + ex2));
					failed = true;
					break;
				}
				if (!flag)
				{
					break;
				}
				yield return steps.Current;
			}
			steps.Dispose();
			if (generation == _generation)
			{
				_building = false;
				if (failed)
				{
					Cleanup();
					_retryBuild = Time.realtimeSinceStartup + 30f;
				}
				else
				{
					Report("Cenario", "PRONTO;" + _environment.Summary + ";sem alterar cidade/nav/portais/saves. Combate aguardando aproximacao.");
				}
			}
		}

		private GameObject Prefab(Kind kind)
		{
			if (_prefabs.TryGetValue(kind, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = "Assets/Generated/" + kind switch
			{
				Kind.Tide => "ExternalIceWolf", 
				Kind.Ember => "ExternalFireWolf", 
				Kind.Stone => "ExternalStoneGolem", 
				_ => "ExternalForestColossus", 
			} + ".prefab";
			foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
			{
				if (!((Object)(object)allLoadedAssetBundle != (Object)null))
				{
					continue;
				}
				string text2 = null;
				string[] allAssetNames = allLoadedAssetBundle.GetAllAssetNames();
				foreach (string text3 in allAssetNames)
				{
					if (string.Equals(text3, text, StringComparison.OrdinalIgnoreCase))
					{
						text2 = text3;
						break;
					}
				}
				if (text2 != null)
				{
					value = allLoadedAssetBundle.LoadAsset<GameObject>(text2);
					if ((Object)(object)value != (Object)null)
					{
						_prefabs[kind] = value;
						return value;
					}
				}
			}
			string text4 = kind switch
			{
				Kind.Tide => "externalicewolf", 
				Kind.Ember => "externalelementalwolf", 
				Kind.Stone => "externalstonegolem", 
				_ => "externalforestcolossus", 
			};
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "..", "Codex_Fenda_Hostil"), text4));
			if ((Object)(object)val == (Object)null)
			{
				throw new IOException("Modelo aprovado indisponivel:" + text4);
			}
			_ownedBundles.Add(val);
			value = val.LoadAsset<GameObject>(text);
			if ((Object)(object)value == (Object)null)
			{
				throw new IOException("Prefab indisponivel:" + text);
			}
			_prefabs[kind] = value;
			return value;
		}

		private unsafe IEnumerator Create(Slot slot, Vector3 surface, int generation)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			_creating = true;
			try
			{
				Prefab(slot.Lot.Kind);
				slot.Body = slot.Template.Spawn(surface + Vector3.up * 0.04f, (string)null, (string)null);
				switch (slot.Lot.Kind)
				{
				case Kind.Stone:
					((Component)slot.Body).gameObject.AddComponent<CodexGolemExterno.InvisibleReceiver>();
					break;
				case Kind.Ember:
					((Component)slot.Body).gameObject.AddComponent<CodexLobosElementais.InvisibleReceiver>();
					break;
				case Kind.Tide:
					((Component)slot.Body).gameObject.AddComponent<CodexLoboGelo.InvisibleReceiver>();
					break;
				default:
					((Component)slot.Body).gameObject.AddComponent<CodexColossoFloresta.InvisibleReceiver>();
					break;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				Clear(slot);
				slot.Retry = Time.realtimeSinceStartup + 15f;
				_creating = false;
				yield break;
			}
			float until = Time.realtimeSinceStartup + 25f;
			while (generation == _generation && (Object)(object)slot.Body != (Object)null && !Ready(slot.Body) && Time.realtimeSinceStartup < until)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(2f);
			if (generation != _generation)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)slot.Body == (Object)null || !Ready(slot.Body))
				{
					throw new InvalidOperationException("Receptor nao inicializou");
				}
				Quaternion val = Quaternion.Euler(0f, (slot.Lot.Kind == Kind.Regent) ? 90f : ((slot.Lot.Point.X + slot.Lot.Point.Z) % 360f), 0f);
				slot.Body.Teleport(surface + Vector3.up * 0.04f, val);
				slot.Body.Invincible = false;
				slot.Body.QuestInvicibility = false;
				slot.Body.QuestNonTargetable = false;
				slot.Body.Stats.SetHealth(slot.Lot.Health);
				slot.Actor = Object.Instantiate<GameObject>(Prefab(slot.Lot.Kind), surface + Vector3.up * 0.04f, val);
				((Object)slot.Actor).name = "ValePrisma_" + slot.Lot.Id;
				_environment.Paint(slot.Actor, slot.Lot.Kind);
				switch (slot.Lot.Kind)
				{
				case Kind.Stone:
					slot.Actor.AddComponent<StoneEnemy>().Initialize(slot.Body);
					break;
				case Kind.Ember:
					slot.Actor.AddComponent<CodexLobosElementais.WolfEnemy>().Initialize(slot.Body);
					break;
				case Kind.Tide:
					slot.Actor.AddComponent<CodexLoboGelo.WolfEnemy>().Initialize(slot.Body);
					break;
				default:
					slot.Actor.AddComponent<ForestEnemy>().Initialize(slot.Body);
					break;
				}
				slot.Complete = true;
				string id = slot.Lot.Id;
				string[] obj = new string[7]
				{
					"PRONTO ",
					slot.Lot.Name,
					";vida=",
					slot.Lot.Health.ToString(),
					";pos=",
					null,
					null
				};
				Vector3 val2 = surface;
				obj[5] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
				obj[6] = ";TAB nativo;contato bloqueavel;sem drops.";
				Report(id, string.Concat(obj));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex2);
				Clear(slot);
				slot.Retry = Time.realtimeSinceStartup + 15f;
			}
			_creating = false;
		}

		private static bool Ready(Character body)
		{
			if ((Object)(object)body.Stats != (Object)null && (Object)(object)body.Animator != (Object)null && body.Hitboxes != null)
			{
				return body.Hitboxes.Length != 0;
			}
			return false;
		}

		internal static Character NearestPlayer(Vector3 point, float radius, bool combat = false)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (!Playable())
			{
				return null;
			}
			if (Time.realtimeSinceStartup >= _playerScan)
			{
				_playerScan = Time.realtimeSinceStartup + 0.1f;
				_players.Clear();
				CharacterManager.Instance.FindCharactersInRange(WorldGround.Origin + new Vector3(-1000f, 0f, 0f), 1500f, ref _players);
			}
			Character result = null;
			float num = radius * radius;
			foreach (Character player in _players)
			{
				if (!((Object)(object)player == (Object)null) && player.IsLocalPlayer && player.Alive && !(((Component)player).transform.position.y < 220f) && (!combat || AllowsDamage(((Component)player).transform.position)))
				{
					Vector3 val = ((Component)player).transform.position - point;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude <= num)
					{
						num = sqrMagnitude;
						result = player;
					}
				}
			}
			return result;
		}

		internal static bool AllowsDamage(Vector3 point)
		{
			//IL_0000: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			if (point.y > 220f)
			{
				return RegionPlan.InRegion(point.x - WorldGround.Origin.x, point.z - WorldGround.Origin.z, 25f);
			}
			return false;
		}

		internal static void Report(string id, string s)
		{
			if (s.StartsWith("ATIVO:", StringComparison.Ordinal))
			{
				s = "ATIVO:rig/IA externos aprovados;vida e posicao autoritativas no PRONTO do lote.";
			}
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogMessage((object)("[ValePrisma:" + id + "] " + s));
			}
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				Cleanup();
			}
		}

		private void Clear(Slot slot)
		{
			if ((Object)(object)slot.Actor != (Object)null)
			{
				Object.Destroy((Object)(object)slot.Actor);
			}
			if ((Object)(object)slot.Body != (Object)null)
			{
				CustomCharacters.DestroyCharacterRPC(slot.Body);
			}
			slot.Actor = null;
			slot.Body = null;
			slot.Complete = false;
		}

		private void Cleanup()
		{
			_generation++;
			((MonoBehaviour)this).StopAllCoroutines();
			foreach (Slot slot in _slots)
			{
				Clear(slot);
				slot.Retry = 0f;
			}
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_environment = null;
			_ground.Clear();
			_building = false;
			_creating = false;
			_scan = 0f;
			_playerScan = -1f;
			_players.Clear();
		}

		private void OnDestroy()
		{
			SL.OnPacksLoaded -= Prepare;
			SceneManager.sceneLoaded -= SceneLoaded;
			Cleanup();
			foreach (Slot slot in _slots)
			{
				if (slot.Template != null)
				{
					slot.Template.Unregister();
				}
			}
			foreach (AssetBundle ownedBundle in _ownedBundles)
			{
				if ((Object)(object)ownedBundle != (Object)null)
				{
					ownedBundle.Unload(true);
				}
			}
			_ownedBundles.Clear();
			_prefabs.Clear();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	internal enum Kind
	{
		Stone,
		Ember,
		Tide,
		Regent
	}
	internal struct Point
	{
		internal readonly float X;

		internal readonly float Z;

		internal Point(float x, float z)
		{
			X = x;
			Z = z;
		}
	}
	internal sealed class Lot
	{
		internal readonly string Id;

		internal readonly string Name;

		internal readonly Kind Kind;

		internal readonly Point Point;

		internal float Health => (Kind == Kind.Regent) ? 1400 : ((Kind == Kind.Stone) ? 360 : ((Kind == Kind.Ember) ? 260 : 300));

		internal float Reservation => (Kind == Kind.Regent) ? 52 : ((Kind == Kind.Stone) ? 52 : 42);

		internal Lot(string id, string name, Kind kind, float x, float z)
		{
			Id = id;
			Name = name;
			Kind = kind;
			Point = new Point(x, z);
		}
	}
	internal static class RegionPlan
	{
		internal const float MinX = -2210f;

		internal const float MaxX = -1890f;

		internal const float MinZ = -210f;

		internal const float MaxZ = 210f;

		internal const float CenterX = -2050f;

		internal const float CenterZ = 0f;

		internal const float ArenaRadius = 34f;

		internal const float RoadWidth = 4.6f;

		internal const int LightBudget = 8;

		internal static readonly Lot[] Lots = new Lot[10]
		{
			new Lot("quartzo_sul", "Sentinela de Quartzo", Kind.Stone, -2140f, -135f),
			new Lot("quartzo_oeste", "Sentinela de Quartzo", Kind.Stone, -2140f, -55f),
			new Lot("quartzo_norte", "Sentinela de Quartzo", Kind.Stone, -2150f, 120f),
			new Lot("brasa_sul", "Sabueso das Brasas", Kind.Ember, -2010f, -145f),
			new Lot("brasa_leste", "Sabueso das Brasas", Kind.Ember, -1945f, -120f),
			new Lot("brasa_ruinas", "Sabueso das Brasas", Kind.Ember, -1955f, -35f),
			new Lot("mare_norte", "Lobo da Mare Mineral", Kind.Tide, -2110f, 155f),
			new Lot("mare_cristal", "Lobo da Mare Mineral", Kind.Tide, -2025f, 150f),
			new Lot("mare_leste", "Lobo da Mare Mineral", Kind.Tide, -1940f, 125f),
			new Lot("regente", "Regente do Prisma", Kind.Regent, -2050f, 0f)
		};

		internal static readonly Point[][] Roads = new Point[5][]
		{
			new Point[14]
			{
				new Point(45f, 43f),
				new Point(66f, 43f),
				new Point(68f, 66f),
				new Point(-75f, 66f),
				new Point(-165f, 66f),
				new Point(-198f, 43f),
				new Point(-218f, 43f),
				new Point(-248f, 43f),
				new Point(-280f, 45f),
				new Point(-340f, 45f),
				new Point(-390f, 45f),
				new Point(-405f, 49.5f),
				new Point(-432f, 49.5f),
				new Point(-440f, 45f)
			},
			new Point[6]
			{
				new Point(-400f, 45f),
				new Point(-400f, 105f),
				new Point(-525f, 105f),
				new Point(-680f, 90f),
				new Point(-790f, 45f),
				new Point(-850f, -38f)
			},
			new Point[11]
			{
				new Point(-790f, 45f),
				new Point(-880f, 135f),
				new Point(-1110f, 170f),
				new Point(-1250f, 170f),
				new Point(-1640f, 170f),
				new Point(-1800f, 160f),
				new Point(-1870f, 135f),
				new Point(-1895f, 50f),
				new Point(-1930f, 12f),
				new Point(-1990f, 0f),
				new Point(-2050f, 0f)
			},
			new Point[5]
			{
				new Point(-1250f, 170f),
				new Point(-1335f, 75f),
				new Point(-1360f, -85f),
				new Point(-1440f, -124f),
				new Point(-1493f, -124f)
			},
			new Point[5]
			{
				new Point(-1640f, 170f),
				new Point(-1650f, 125f),
				new Point(-1725f, -5f),
				new Point(-1800f, -5f),
				new Point(-1800f, 25f)
			}
		};

		internal static float Distance(Point a, Point b)
		{
			float num = a.X - b.X;
			float num2 = a.Z - b.Z;
			return (float)Math.Sqrt(num * num + num2 * num2);
		}

		internal static float SegmentDistance(Point p, Point a, Point b)
		{
			float num = b.X - a.X;
			float num2 = b.Z - a.Z;
			float num3 = num * num + num2 * num2;
			float num4 = ((num3 < 0.001f) ? 0f : Math.Max(0f, Math.Min(1f, ((p.X - a.X) * num + (p.Z - a.Z) * num2) / num3)));
			return Distance(p, new Point(a.X + num4 * num, a.Z + num4 * num2));
		}

		internal static bool InRegion(float x, float z, float margin = 0f)
		{
			if (x >= -2210f - margin && x <= -1890f + margin && z >= -210f - margin)
			{
				return z <= 210f + margin;
			}
			return false;
		}

		internal static bool PropAllowed(Point p, float radius)
		{
			if (!InRegion(p.X, p.Z, 0f - radius - 3f))
			{
				return false;
			}
			Lot[] lots = Lots;
			foreach (Lot lot in lots)
			{
				if (Distance(p, lot.Point) < lot.Reservation + radius)
				{
					return false;
				}
			}
			Point[][] roads = Roads;
			foreach (Point[] array in roads)
			{
				for (int j = 1; j < array.Length; j++)
				{
					if (SegmentDistance(p, array[j - 1], array[j]) < 6f + radius)
					{
						return false;
					}
				}
			}
			return true;
		}

		internal static bool RoadPostAllowed(Point p)
		{
			if (Math.Abs(p.X + 450f) < 51f && Math.Abs(p.Z - 45f) < 40f)
			{
				return false;
			}
			if (Math.Abs(p.X + 850f) < 70f && Math.Abs(p.Z + 76f) < 75f)
			{
				return false;
			}
			if (Distance(p, new Point(-1800f, 78f)) < 46f)
			{
				return false;
			}
			Point[] array = new Point[12]
			{
				new Point(-888f, -90f),
				new Point(-845f, -68f),
				new Point(-869f, -27f),
				new Point(-760f, -146f),
				new Point(-950f, -111f),
				new Point(-945f, -4f),
				new Point(-765f, 16f),
				new Point(-675f, -61f),
				new Point(-1060f, -54f),
				new Point(-1050f, -176f),
				new Point(-1160f, 24f),
				new Point(-585f, -151f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				int num;
				switch (i)
				{
				default:
					num = 43;
					break;
				case 6:
				case 10:
					num = 45;
					break;
				case 1:
				case 3:
				case 8:
					num = 53;
					break;
				}
				float num2 = num;
				if (Distance(p, array[i]) < num2)
				{
					return false;
				}
			}
			Point[] array2 = new Point[7]
			{
				new Point(-1465f, -168f),
				new Point(-1572f, -86f),
				new Point(-1468f, -58f),
				new Point(-1562f, -184f),
				new Point(-1420f, -112f),
				new Point(-1508f, -206f),
				new Point(-1582f, -144f)
			};
			foreach (Point b in array2)
			{
				if (Distance(p, b) < 32f)
				{
					return false;
				}
			}
			array2 = new Point[4]
			{
				new Point(-1540f, -130f),
				new Point(-1400f, -149f),
				new Point(-1480f, -219f),
				new Point(-1494f, -39f)
			};
			foreach (Point b2 in array2)
			{
				if (Distance(p, b2) < 18f)
				{
					return false;
				}
			}
			array2 = new Point[9]
			{
				new Point(52f, 43f),
				new Point(-28f, 38f),
				new Point(-43f, -5.1f),
				new Point(-15f, 38f),
				new Point(108f, 54f),
				new Point(129f, 57f),
				new Point(93f, 72f),
				new Point(97f, 72f),
				new Point(101f, 68f)
			};
			foreach (Point b3 in array2)
			{
				if (Distance(p, b3) < 7f)
				{
					return false;
				}
			}
			array2 = new Point[7]
			{
				new Point(-1529f, -94f),
				new Point(-1487f, -94f),
				new Point(-1510f, -77f),
				new Point(-1505f, -116f),
				new Point(-1800f, 100f),
				new Point(-80f, 17f),
				new Point(-400f, 55f)
			};
			foreach (Point b4 in array2)
			{
				if (Distance(p, b4) < 3f)
				{
					return false;
				}
			}
			Point[] array3 = Roads[0];
			for (int k = 1; k < array3.Length; k++)
			{
				if (SegmentDistance(p, array3[k - 1], array3[k]) < 4.2f)
				{
					return false;
				}
			}
			if (InRegion(p.X, p.Z))
			{
				Lot[] lots = Lots;
				foreach (Lot lot in lots)
				{
					if (Distance(p, lot.Point) < lot.Reservation + 2f)
					{
						return false;
					}
				}
			}
			return true;
		}

		internal static Point[] NatureSites()
		{
			List<Point> list = new List<Point>();
			Random random = new Random(20261010);
			for (int i = 0; i < 12000; i++)
			{
				if (list.Count >= 32)
				{
					break;
				}
				Point point = new Point(-2200f + (float)random.NextDouble() * 300f, -200f + (float)random.NextDouble() * 400f);
				if (!PropAllowed(point, 6f))
				{
					continue;
				}
				bool flag = true;
				foreach (Point item in list)
				{
					if (Distance(point, item) < 15f)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					list.Add(point);
				}
			}
			if (list.Count != 32)
			{
				throw new InvalidOperationException("Insufficient reserved scenery lots");
			}
			return list.ToArray();
		}
	}
	internal struct SurfacePoint
	{
		internal float X;

		internal float Y;

		internal float Z;

		internal SurfacePoint(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}
	}
	internal static class RoadGeometry
	{
		private static float Side(Point a, Point b, SurfacePoint p)
		{
			return (b.X - a.X) * (p.Z - a.Z) - (b.Z - a.Z) * (p.X - a.X);
		}

		internal static List<SurfacePoint> Clip(SurfacePoint a, SurfacePoint b, SurfacePoint c, Point from, Point to, float width)
		{
			float num = to.X - from.X;
			float num2 = to.Z - from.Z;
			float num3 = (float)Math.Sqrt(num * num + num2 * num2);
			if (num3 < 0.0001f)
			{
				return new List<SurfacePoint>();
			}
			float num4 = (0f - num2) / num3 * width / 2f;
			float num5 = num / num3 * width / 2f;
			Point[] array = new Point[4]
			{
				new Point(from.X - num4, from.Z - num5),
				new Point(to.X - num4, to.Z - num5),
				new Point(to.X + num4, to.Z + num5),
				new Point(from.X + num4, from.Z + num5)
			};
			List<SurfacePoint> list = new List<SurfacePoint> { a, b, c };
			for (int i = 0; i < 4; i++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				List<SurfacePoint> list2 = new List<SurfacePoint>();
				Point a2 = array[i];
				Point b2 = array[(i + 1) % 4];
				SurfacePoint p = list[list.Count - 1];
				float num6 = Side(a2, b2, p);
				foreach (SurfacePoint item in list)
				{
					float num7 = Side(a2, b2, item);
					bool num8 = num6 >= -1E-05f;
					bool flag = num7 >= -1E-05f;
					if (num8 != flag)
					{
						float num9 = Math.Max(0f, Math.Min(1f, num6 / (num6 - num7)));
						list2.Add(new SurfacePoint(p.X + (item.X - p.X) * num9, p.Y + (item.Y - p.Y) * num9, p.Z + (item.Z - p.Z) * num9));
					}
					if (flag)
					{
						list2.Add(item);
					}
					p = item;
					num6 = num7;
				}
				list = list2;
			}
			return list;
		}
	}
	internal sealed class WorldGround
	{
		internal sealed class Face
		{
			internal SurfacePoint A;

			internal SurfacePoint B;

			internal SurfacePoint C;

			internal Collider Floor;
		}

		internal static readonly Vector3 Origin = new Vector3(1783f, 255f, 1796.7f);

		private readonly List<Collider> _floors = new List<Collider>();

		private readonly Dictionary<Tuple<int, int>, List<Face>> _faces = new Dictionary<Tuple<int, int>, List<Face>>();

		internal void Clear()
		{
			_floors.Clear();
			_faces.Clear();
		}

		internal void CacheFaces()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			_faces.Clear();
			Vector3 a = default(Vector3);
			Vector3 val2 = default(Vector3);
			Vector3 b = default(Vector3);
			Vector3 c = default(Vector3);
			foreach (Collider floor in _floors)
			{
				if ((Object)(object)floor == (Object)null)
				{
					continue;
				}
				MeshCollider val = (MeshCollider)(object)((floor is MeshCollider) ? floor : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val.sharedMesh != (Object)null)
				{
					Mesh sharedMesh = val.sharedMesh;
					Vector3[] vertices = sharedMesh.vertices;
					int[] triangles = sharedMesh.triangles;
					for (int i = 0; i < triangles.Length; i += 3)
					{
						AddFace(floor, ((Component)floor).transform.TransformPoint(vertices[triangles[i]]), ((Component)floor).transform.TransformPoint(vertices[triangles[i + 1]]), ((Component)floor).transform.TransformPoint(vertices[triangles[i + 2]]));
					}
				}
				else if (floor is BoxCollider)
				{
					Bounds bounds = floor.bounds;
					((Vector3)(ref a))..ctor(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).min.z);
					((Vector3)(ref val2))..ctor(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).min.z);
					((Vector3)(ref b))..ctor(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).max.z);
					((Vector3)(ref c))..ctor(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).max.z);
					AddFace(floor, a, b, val2);
					AddFace(floor, val2, b, c);
				}
			}
		}

		private void AddFace(Collider floor, 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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)
			Vector3 val = Vector3.Cross(b - a, c - a);
			if (((Vector3)(ref val)).normalized.y < 0.75f)
			{
				return;
			}
			a -= Origin;
			b -= Origin;
			c -= Origin;
			Face item = new Face
			{
				Floor = floor,
				A = new SurfacePoint(a.x, a.y, a.z),
				B = new SurfacePoint(b.x, b.y, b.z),
				C = new SurfacePoint(c.x, c.y, c.z)
			};
			int num = Mathf.FloorToInt(Mathf.Min(a.x, Mathf.Min(b.x, c.x)) / 10f);
			int num2 = Mathf.FloorToInt(Mathf.Max(a.x, Mathf.Max(b.x, c.x)) / 10f);
			int num3 = Mathf.FloorToInt(Mathf.Min(a.z, Mathf.Min(b.z, c.z)) / 10f);
			int num4 = Mathf.FloorToInt(Mathf.Max(a.z, Mathf.Max(b.z, c.z)) / 10f);
			for (int i = num; i <= num2; i++)
			{
				for (int j = num3; j <= num4; j++)
				{
					Tuple<int, int> key = Tuple.Create(i, j);
					if (!_faces.TryGetValue(key, out var value))
					{
						value = new List<Face>();
						_faces[key] = value;
					}
					value.Add(item);
				}
			}
		}

		internal IEnumerable<Face> Faces(Point a, Point b, float width)
		{
			HashSet<Face> seen = new HashSet<Face>();
			int num = Mathf.FloorToInt((Mathf.Min(a.X, b.X) - width) / 10f);
			int x1 = Mathf.FloorToInt((Mathf.Max(a.X, b.X) + width) / 10f);
			int z0 = Mathf.FloorToInt((Mathf.Min(a.Z, b.Z) - width) / 10f);
			int z1 = Mathf.FloorToInt((Mathf.Max(a.Z, b.Z) + width) / 10f);
			for (int i = num; i <= x1; i++)
			{
				for (int j = z0; j <= z1; j++)
				{
					if (!_faces.TryGetValue(Tuple.Create(i, j), out var value))
					{
						continue;
					}
					foreach (Face item in value)
					{
						if ((Object)(object)item.Floor != (Object)null && seen.Add(item))
						{
							yield return item;
						}
					}
				}
			}
		}

		internal bool Refresh()
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			_floors.Clear();
			Collider[] array = Object.FindObjectsOfType<Collider>();
			foreach (Collider val in array)
			{
				if (IsFloor(val) && val.enabled)
				{
					Bounds bounds = val.bounds;
					if (((Bounds)(ref bounds)).max.y > 220f)
					{
						_floors.Add(val);
					}
				}
			}
			Vector3 surface;
			Collider floor;
			if (_floors.Count >= 64)
			{
				return Sample(new Point(-2050f, 0f), out surface, out floor);
			}
			return false;
		}

		internal static bool IsFloor(Collider c)
		{
			if ((Object)(object)c != (Object)null)
			{
				if (!((Object)c).name.StartsWith("Campo_Oeste_Setor_", StringComparison.Ordinal) && !(((Object)c).name == "Piso_Principal_Colisor") && !(((Object)c).name == "Campo_Branco_Cidade") && !(((Object)c).name == "Solo_Neve_Continuo") && !(((Object)c).name == "Neve_Pe_Canion") && !(((Object)c).name == "Passagem_Oeste_Canion") && !(((Object)c).name == "Neve_Exterior_Canion") && !(((Object)c).name == "CampoMecanico_Arena_Piso"))
				{
					return ((Object)c).name.StartsWith("Pantano_Passarela", StringComparison.Ordinal);
				}
				return true;
			}
			return false;
		}

		internal bool Sample(Point p, out Vector3 surface, out Collider floor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002