Decompiled source of RuneTraps v0.4.1

RuneTraps.dll

Decompiled 4 hours 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 HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.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 RuneTraps
{
	internal static class RuneArt
	{
		private const string ResourcePrefix = "RuneTraps.Assets.";

		private static Mesh _quad;

		private static MethodInfo _loadImage;

		public static void LoadAll()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			RuneKind[] all = RuneKinds.All;
			foreach (RuneKind runeKind in all)
			{
				runeKind.Texture = LoadEmbedded(runeKind.Resource);
				if ((Object)(object)runeKind.Texture == (Object)null)
				{
					RuneTrapsPlugin.Log.LogWarning((object)("Arte '" + runeKind.Resource + ".png' não encontrada; usando um desenho simples no lugar."));
					runeKind.Texture = CreateFallbackTexture(256, runeKind.LightColor);
				}
			}
		}

		public static Texture2D LoadTexture(string name)
		{
			return LoadEmbedded(name);
		}

		private static Texture2D LoadEmbedded(string name)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name2 = "RuneTraps.Assets." + name + ".png";
				using Stream stream = executingAssembly.GetManifestResourceStream(name2);
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num <= 0)
					{
						break;
					}
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
				if (!LoadImageReflect(val, array))
				{
					return null;
				}
				((Object)val).name = "RuneTraps_" + name;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)2;
				((Texture)val).anisoLevel = 8;
				((Object)val).hideFlags = (HideFlags)32;
				return val;
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Erro ao carregar a arte '" + name + "': " + ex.Message));
				return null;
			}
		}

		private static Texture2D CreateFallbackTexture(int size, Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0034: 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_004e: 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_00e2: 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)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			((Object)val).hideFlags = (HideFlags)32;
			Color32[] array = (Color32[])(object)new Color32[size * size];
			float num = (float)size * 0.5f;
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor((byte)(color.r * 255f), (byte)(color.g * 255f), (byte)(color.b * 255f), byte.MaxValue);
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num2 = ((float)j + 0.5f - num) / num;
					float num3 = ((float)i + 0.5f - num) / num;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					bool flag = (num4 > 0.9f && num4 < 0.97f) || (num4 > 0.72f && num4 < 0.76f) || num4 < 0.08f;
					array[i * size + j] = (Color32)(flag ? val2 : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
				}
			}
			val.SetPixels32(array);
			val.Apply(true, false);
			return val;
		}

		public static Mesh GetQuadMesh()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_008d: 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_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_00c5: 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_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_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_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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			if ((Object)(object)_quad != (Object)null)
			{
				return _quad;
			}
			Mesh val = new Mesh();
			((Object)val).name = "RuneTraps_Quad";
			val.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f)
			};
			val.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f)
			};
			val.normals = (Vector3[])(object)new Vector3[4]
			{
				Vector3.back,
				Vector3.back,
				Vector3.back,
				Vector3.back
			};
			val.triangles = new int[6] { 0, 2, 1, 2, 3, 1 };
			val.RecalculateBounds();
			((Object)val).hideFlags = (HideFlags)32;
			_quad = val;
			return val;
		}

		public static Material CreateMaterial()
		{
			//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_0087: 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_009d: Expected O, but got Unknown
			string[] obj = new string[4] { "Sprites/Default", "Legacy Shaders/Particles/Alpha Blended", "Unlit/Transparent", "Standard" };
			Shader val = null;
			string[] array = obj;
			for (int i = 0; i < array.Length; i++)
			{
				val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				RuneTrapsPlugin.Log.LogWarning((object)"Nenhum shader encontrado para a runa; usando o shader padrão.");
				val = Shader.Find("Hidden/InternalErrorShader");
			}
			return new Material(val)
			{
				color = new Color(1f, 1f, 1f, 0f),
				renderQueue = 3000
			};
		}

		internal static bool LoadImageReflect(Texture2D tex, byte[] bytes)
		{
			if (_loadImage == null)
			{
				Type type = AccessTools.TypeByName("UnityEngine.ImageConversion");
				if (type != null)
				{
					_loadImage = type.GetMethod("LoadImage", new Type[3]
					{
						typeof(Texture2D),
						typeof(byte[]),
						typeof(bool)
					});
				}
			}
			if (_loadImage == null)
			{
				return false;
			}
			return (bool)_loadImage.Invoke(null, new object[3] { tex, bytes, false });
		}
	}
	internal class RuneKind
	{
		public int Index;

		public string Id;

		public string Resource;

		public string Token;

		public Color LightColor;

		public float DefFire;

		public float DefFrost;

		public float DefLightning;

		public float DefPoison;

		public float DefBlunt;

		public float DefRadius;

		public float DefPush;

		public ConfigEntry<float> Fire;

		public ConfigEntry<float> Frost;

		public ConfigEntry<float> Lightning;

		public ConfigEntry<float> Poison;

		public ConfigEntry<float> Blunt;

		public ConfigEntry<float> Radius;

		public ConfigEntry<float> Push;

		public Texture2D Texture;
	}
	internal static class RuneKinds
	{
		public static RuneKind[] All;

		public static RuneKind Get(int index)
		{
			if (All == null || All.Length == 0)
			{
				return null;
			}
			return All[Mathf.Clamp(index, 0, All.Length - 1)];
		}

		public static void Init(ConfigFile cfg)
		{
			//IL_0027: 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_00c5: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			All = new RuneKind[5]
			{
				Make(0, "Fogo", "runa_de_fogo", "$rune_fire", new Color(1f, 0.8f, 0.15f), 60f),
				Make(1, "Gelo", "runa_de_gelo", "$rune_frost", new Color(0.2f, 1f, 0.9f), 0f, 55f),
				Make(2, "Raio", "runa_de_raio", "$rune_lightning", new Color(0.7f, 0.3f, 1f), 0f, 0f, 65f),
				Make(3, "Veneno", "runa_de_veneno", "$rune_poison", new Color(0.25f, 1f, 0.25f), 0f, 0f, 0f, 45f),
				Make(4, "Explosiva", "runa_explosiva", "$rune_explosive", new Color(1f, 0.15f, 0.1f), 60f, 0f, 0f, 0f, 60f, 6f, 70f)
			};
			RuneKind[] all = All;
			foreach (RuneKind k in all)
			{
				Bind(cfg, k);
			}
		}

		private static RuneKind Make(int index, string id, string resource, string token, Color light, float fire = 0f, float frost = 0f, float lightning = 0f, float poison = 0f, float blunt = 0f, float radius = 4f, float push = 30f)
		{
			//IL_0022: 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)
			return new RuneKind
			{
				Index = index,
				Id = id,
				Resource = resource,
				Token = token,
				LightColor = light,
				DefFire = fire,
				DefFrost = frost,
				DefLightning = lightning,
				DefPoison = poison,
				DefBlunt = blunt,
				DefRadius = radius,
				DefPush = push
			};
		}

		private static ConfigEntry<float> B(ConfigFile cfg, string section, string key, float def, string desc)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			return cfg.Bind<float>(section, key, def, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
		}

		private static void Bind(ConfigFile cfg, RuneKind k)
		{
			string section = "2 - Runa " + k.Id;
			k.Fire = B(cfg, section, "DanoDeFogo", k.DefFire, "Dano de fogo base.");
			k.Frost = B(cfg, section, "DanoDeGelo", k.DefFrost, "Dano de gelo base (também deixa o inimigo lento).");
			k.Lightning = B(cfg, section, "DanoDeRaio", k.DefLightning, "Dano de relâmpago base.");
			k.Poison = B(cfg, section, "DanoDeVeneno", k.DefPoison, "Dano de veneno base (continua causando dano com o tempo).");
			k.Blunt = B(cfg, section, "DanoContundente", k.DefBlunt, "Dano contundente base.");
			k.Radius = B(cfg, section, "RaioDaExplosao", k.DefRadius, "Raio (m) do dano quando a runa explode.");
			k.Push = B(cfg, section, "ForcaDeEmpurrao", k.DefPush, "Empurrão aplicado aos inimigos atingidos.");
		}
	}
	internal static class RuneStaffModel
	{
		private struct Box
		{
			public Vector3 Min;

			public Vector3 Max;

			public bool Valid;
		}

		private const string Prefix = "RuneTraps.Assets.";

		private const float BaseScale = 0.75f;

		public static ConfigEntry<bool> UseModel;

		public static ConfigEntry<bool> UseNormalMap;

		public static ConfigEntry<float> SizeFactor;

		public static ConfigEntry<bool> FlipHead;

		private static Mesh _mesh;

		private static Material _mat;

		public static void Init(ConfigFile cfg)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			UseModel = cfg.Bind<bool>("5 - Visual", "UsarModeloNovo", true, new ConfigDescription("Usa o modelo 3D novo do cajado. Desligue para voltar ao modelo do cajado base do jogo.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
			UseNormalMap = cfg.Bind<bool>("5 - Visual", "UsarMapaDeNormal", true, new ConfigDescription("Usa o mapa de relevo do modelo. Se o cajado parecer com a luz estranha, desligue.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
			SizeFactor = cfg.Bind<float>("5 - Visual", "TamanhoDoModelo", 1f, new ConfigDescription("Multiplicador extra de tamanho do cajado novo (1 = tamanho padrão do mod, que já é 25% menor que o cajado base).", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
			FlipHead = cfg.Bind<bool>("5 - Visual", "InverterPonta", false, new ConfigDescription("Se o cajado aparecer de cabeça para baixo na mão, ligue esta opção.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
		}

		private static byte[] ReadResource(string file)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RuneTraps.Assets." + file);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num <= 0)
				{
					break;
				}
			}
			return array;
		}

		private static Texture2D LoadTex(string file, bool linear)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			byte[] array = ReadResource(file);
			if (array == null)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Textura '" + file + "' não encontrada."));
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
			if (!RuneArt.LoadImageReflect(val, array))
			{
				return null;
			}
			((Object)val).name = "RuneTraps_" + file;
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static Mesh BuildMesh()
		{
			//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_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_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_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_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_0131: 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_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_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_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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			if ((Object)(object)_mesh != (Object)null)
			{
				return _mesh;
			}
			byte[] array = ReadResource("cajado_malha.bin");
			if (array == null)
			{
				return null;
			}
			using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(array)))
			{
				int num = binaryReader.ReadInt32();
				int num2 = binaryReader.ReadInt32();
				Vector3[] array2 = (Vector3[])(object)new Vector3[num];
				Vector3[] array3 = (Vector3[])(object)new Vector3[num];
				Vector2[] array4 = (Vector2[])(object)new Vector2[num];
				for (int i = 0; i < num; i++)
				{
					array2[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					array3[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					array4[i] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				int[] array5 = new int[num2];
				for (int j = 0; j < num2; j++)
				{
					array5[j] = binaryReader.ReadUInt16();
				}
				Vector3[] array6 = (Vector3[])(object)new Vector3[num * 2];
				Vector3[] array7 = (Vector3[])(object)new Vector3[num * 2];
				Vector2[] array8 = (Vector2[])(object)new Vector2[num * 2];
				for (int k = 0; k < num; k++)
				{
					array6[k] = array2[k];
					array7[k] = array3[k];
					array8[k] = array4[k];
					array6[k + num] = array2[k];
					array7[k + num] = -array3[k];
					array8[k + num] = array4[k];
				}
				int[] array9 = new int[num2 * 2];
				for (int l = 0; l < num2; l += 3)
				{
					array9[l] = array5[l];
					array9[l + 1] = array5[l + 1];
					array9[l + 2] = array5[l + 2];
					array9[num2 + l] = array5[l] + num;
					array9[num2 + l + 1] = array5[l + 2] + num;
					array9[num2 + l + 2] = array5[l + 1] + num;
				}
				Mesh val = new Mesh();
				((Object)val).name = "RuneTraps_Cajado";
				if (array6.Length > 60000)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.vertices = array6;
				val.normals = array7;
				val.uv = array8;
				val.triangles = array9;
				val.RecalculateTangents();
				val.RecalculateBounds();
				((Object)val).hideFlags = (HideFlags)32;
				_mesh = val;
			}
			return _mesh;
		}

		private static Material BuildMaterial()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_mat != (Object)null)
			{
				return _mat;
			}
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Legacy Shaders/Diffuse");
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val);
			((Object)val2).name = "RuneTraps_Cajado";
			Texture2D val3 = LoadTex("cajado_cor.jpg", linear: false);
			if ((Object)(object)val3 == (Object)null)
			{
				return null;
			}
			val2.SetTexture("_MainTex", (Texture)(object)val3);
			if (UseNormalMap.Value)
			{
				Texture2D val4 = LoadTex("cajado_normal.png", linear: true);
				if ((Object)(object)val4 != (Object)null)
				{
					val2.SetTexture("_BumpMap", (Texture)(object)val4);
					val2.EnableKeyword("_NORMALMAP");
				}
			}
			Texture2D val5 = LoadTex("cajado_metal.png", linear: true);
			if ((Object)(object)val5 != (Object)null)
			{
				val2.SetTexture("_MetallicGlossMap", (Texture)(object)val5);
				val2.EnableKeyword("_METALLICGLOSSMAP");
				val2.SetFloat("_Metallic", 1f);
				val2.SetFloat("_Glossiness", 0.8f);
			}
			Texture2D val6 = LoadTex("cajado_emissao.jpg", linear: false);
			if ((Object)(object)val6 != (Object)null)
			{
				val2.SetTexture("_EmissionMap", (Texture)(object)val6);
				val2.SetColor("_EmissionColor", new Color(1.6f, 1.6f, 1.6f));
				val2.EnableKeyword("_EMISSION");
				val2.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
			}
			_mat = val2;
			return val2;
		}

		private static void Grow(ref Box b, Vector3 p)
		{
			//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_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_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_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_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_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 (!b.Valid)
			{
				b.Min = (b.Max = p);
				b.Valid = true;
			}
			else
			{
				b.Min = Vector3.Min(b.Min, p);
				b.Max = Vector3.Max(b.Max, p);
			}
		}

		private static Box LocalBounds(Transform root, Transform scope)
		{
			//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_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_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_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_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_00c5: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			Box b = default(Box);
			Renderer[] componentsInChildren = ((Component)scope).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Mesh val2 = null;
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null)
				{
					val2 = component.sharedMesh;
				}
				SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
				if ((Object)(object)val3 != (Object)null)
				{
					val2 = val3.sharedMesh;
				}
				if (!((Object)(object)val2 == (Object)null))
				{
					Bounds bounds = val2.bounds;
					Matrix4x4 val4 = root.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
					for (int j = 0; j < 8; j++)
					{
						Vector3 val5 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
						Grow(ref b, ((Matrix4x4)(ref val4)).MultiplyPoint3x4(val5));
					}
				}
			}
			return b;
		}

		private static void StripVisuals(Transform t, Transform skip)
		{
			Component[] componentsInChildren = ((Component)t).GetComponentsInChildren<Component>(true);
			Component[] array = componentsInChildren;
			foreach (Component val in array)
			{
				if (!((Object)(object)val == (Object)null) && (!((Object)(object)skip != (Object)null) || !val.transform.IsChildOf(skip)) && (val is Renderer || val is LODGroup))
				{
					Object.DestroyImmediate((Object)(object)val);
				}
			}
			array = componentsInChildren;
			foreach (Component val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null) && (!((Object)(object)skip != (Object)null) || !val2.transform.IsChildOf(skip)) && (val2 is MeshFilter || val2 is Light || ((object)val2).GetType().Name == "ParticleSystem"))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
		}

		private static void AddModel(Transform parent, Transform root, Box vanilla)
		{
			//IL_0020: 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_0032: 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_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_0050: 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_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_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_00c3: 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)
			//IL_011c: 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_0129: 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_0140: 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_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_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_015f: 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)
			Mesh val = BuildMesh();
			Material val2 = BuildMaterial();
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
			{
				Vector3 val3 = vanilla.Max - vanilla.Min;
				Vector3 val4 = (vanilla.Max + vanilla.Min) * 0.5f;
				int num = 1;
				if (val3.x > ((Vector3)(ref val3))[num])
				{
					num = 0;
				}
				if (val3.z > ((Vector3)(ref val3))[num])
				{
					num = 2;
				}
				float num2 = ((((Vector3)(ref val4))[num] >= -0.02f) ? 1f : (-1f));
				if (FlipHead.Value)
				{
					num2 = 0f - num2;
				}
				Vector3 zero = Vector3.zero;
				((Vector3)(ref zero))[num] = num2;
				Bounds bounds = val.bounds;
				float y = ((Bounds)(ref bounds)).size.y;
				float num3 = ((((Vector3)(ref val3))[num] > 0.1f) ? ((Vector3)(ref val3))[num] : 1.8f) / y * 0.75f * SizeFactor.Value;
				GameObject val5 = new GameObject("RuneStaffModel");
				val5.transform.SetParent(parent, false);
				val5.transform.localRotation = Quaternion.FromToRotation(Vector3.up, zero);
				val5.transform.localScale = Vector3.one * num3;
				Vector3 localPosition = parent.InverseTransformPoint(root.TransformPoint(val4));
				val5.transform.localPosition = localPosition;
				val5.AddComponent<MeshFilter>().sharedMesh = val;
				MeshRenderer obj = val5.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = val2;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
				((Renderer)obj).receiveShadows = true;
			}
		}

		public static void Apply(GameObject prefab)
		{
			//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)
			if (UseModel == null || !UseModel.Value || (Object)(object)prefab == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)BuildMesh() == (Object)null || (Object)(object)BuildMaterial() == (Object)null)
				{
					RuneTrapsPlugin.Log.LogWarning((object)"Modelo 3D do cajado não carregou; mantendo o modelo base.");
					return;
				}
				Transform transform = prefab.transform;
				Transform val = transform.Find("attach");
				if ((Object)(object)val != (Object)null)
				{
					Box box = LocalBounds(transform, val);
					if (box.Valid)
					{
						Box box2 = LocalBounds(val, val);
						StripVisuals(val, null);
						AddModel(val, val, box2.Valid ? box2 : box);
					}
				}
				Box b = default(Box);
				Renderer[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val2 in componentsInChildren)
				{
					if (!((Object)(object)val != (Object)null) || !((Component)val2).transform.IsChildOf(val))
					{
						Box box3 = LocalBounds(transform, ((Component)val2).transform);
						if (box3.Valid)
						{
							Grow(ref b, box3.Min);
							Grow(ref b, box3.Max);
						}
					}
				}
				if (b.Valid)
				{
					StripVisuals(transform, val);
					AddModel(transform, transform, b);
				}
				RuneTrapsPlugin.Log.LogInfo((object)("Modelo 3D do cajado aplicado (" + (((Object)(object)_mesh != (Object)null) ? _mesh.vertexCount : 0) + " vértices)."));
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Falha ao aplicar o modelo 3D do cajado: " + ex));
			}
		}
	}
	internal class UpgradeItem
	{
		public string Prefab;

		public int Amount;

		public ItemDrop Drop;
	}
	internal class UpgradeTier
	{
		public int Quality;

		public string Id;

		public string DisplayName;

		public bool Galdr;

		public string DefaultItems;

		public ConfigEntry<string> Items;

		public List<UpgradeItem> Resolved = new List<UpgradeItem>();
	}
	internal static class RuneStaffUpgrades
	{
		public const int MaxQuality = 7;

		public const int Slots = 4;

		public static UpgradeTier[] Tiers;

		public static ConfigEntry<float> BonusPerLevel;

		public static ConfigEntry<int> GaldrLevel;

		private static Recipe _recipe;

		private static ItemDrop[] _baseDrops;

		private static int _applied = -1;

		private static CraftingStation _galdr;

		private static bool _tickErrorLogged;

		private static int _applyLogs;

		private static UpgradeTier Tier(int quality, string id, string name, bool galdr, string items)
		{
			return new UpgradeTier
			{
				Quality = quality,
				Id = id,
				DisplayName = name,
				Galdr = galdr,
				DefaultItems = items
			};
		}

		public static void Init(ConfigFile cfg)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			Tiers = new UpgradeTier[6]
			{
				Tier(2, "Pantano", "Pântano", galdr: false, "Iron:10,ElderBark:10,WitheredBone:5"),
				Tier(3, "Montanhas", "Montanhas", galdr: false, "Silver:10,Obsidian:8,WolfFang:2,DragonTear:1"),
				Tier(4, "Planicies", "Planícies", galdr: false, "BlackMetal:10,LinenThread:5,GoblinTotem:1,YagluthDrop:1"),
				Tier(5, "TerrasNebulosas", "Terras Nebulosas", galdr: true, "Eitr:10,BlackMarble:10,BlackCore:2,YggdrasilWood:5"),
				Tier(6, "TerrasCinzentas", "Terras Cinzentas", galdr: true, "FlametalNew:10,CharredBone:10,Blackwood:5,TrophyAsksvin:1"),
				Tier(7, "ExtremoNorte", "Extremo Norte", galdr: true, "Gold:12,OrbFrostFire:2,OrbThunderBlood:2")
			};
			BonusPerLevel = cfg.Bind<float>("4 - Upgrades", "BonusPorUpgrade", 0.25f, new ConfigDescription("Quanto cada upgrade soma à potência das runas (0.25 = +25%).", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
			GaldrLevel = cfg.Bind<int>("4 - Upgrades", "NivelDaMesaDeGaldr", 1, new ConfigDescription("Nível mínimo da Mesa de Galdr para os upgrades das Terras Nebulosas em diante.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
			UpgradeTier[] tiers = Tiers;
			foreach (UpgradeTier upgradeTier in tiers)
			{
				upgradeTier.Items = cfg.Bind<string>("4 - Upgrades", "Nivel" + upgradeTier.Quality + "_" + upgradeTier.Id + "_Itens", upgradeTier.DefaultItems, new ConfigDescription("Itens do upgrade de " + upgradeTier.DisplayName + " (" + (upgradeTier.Galdr ? "Mesa de Galdr" : "Forja") + "). Formato: Prefab:quantidade,Prefab:quantidade (máximo 4 itens). Use o comando de console 'runetraps_itens <texto>' para descobrir os nomes internos.", (AcceptableValueBase)null, new object[1]
				{
					new ConfigurationManagerAttributes()
				}));
			}
		}

		private static GameObject FindItemPrefab(string name)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(name);
			if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<ItemDrop>() != (Object)null)
			{
				return prefab;
			}
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			GameObject val = null;
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				if (!((Object)(object)item == (Object)null) && !((Object)(object)item.GetComponent<ItemDrop>() == (Object)null))
				{
					if (string.Equals(((Object)item).name, name, StringComparison.OrdinalIgnoreCase))
					{
						return item;
					}
					if (((Object)item).name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0 && ((Object)(object)val == (Object)null || ((Object)item).name.Length < ((Object)val).name.Length))
					{
						val = item;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Item '" + name + "' não existe com esse nome exato; usando '" + ((Object)val).name + "'."));
			}
			return val;
		}

		public static void Resolve()
		{
			UpgradeTier[] tiers = Tiers;
			foreach (UpgradeTier upgradeTier in tiers)
			{
				upgradeTier.Resolved.Clear();
				string[] array = upgradeTier.Items.Value.Split(new char[1] { ',' });
				for (int j = 0; j < array.Length; j++)
				{
					string text = array[j].Trim();
					if (text.Length != 0)
					{
						string text2 = text;
						int result = 1;
						int num = text.IndexOf(':');
						if (num > 0)
						{
							text2 = text.Substring(0, num).Trim();
							int.TryParse(text.Substring(num + 1).Trim(), out result);
						}
						result = Mathf.Clamp(result, 1, 999);
						GameObject val = FindItemPrefab(text2);
						ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
						if ((Object)(object)val2 == (Object)null)
						{
							RuneTrapsPlugin.Log.LogWarning((object)("Upgrade " + upgradeTier.DisplayName + ": item '" + text2 + "' não existe e foi ignorado. Corrija na config."));
						}
						else if (upgradeTier.Resolved.Count >= 4)
						{
							RuneTrapsPlugin.Log.LogWarning((object)("Upgrade " + upgradeTier.DisplayName + ": só " + 4 + " itens cabem; '" + text2 + "' foi ignorado."));
						}
						else
						{
							upgradeTier.Resolved.Add(new UpgradeItem
							{
								Prefab = text2,
								Amount = result,
								Drop = val2
							});
						}
					}
				}
				if (upgradeTier.Resolved.Count == 0)
				{
					GameObject prefab = PrefabManager.Instance.GetPrefab("Coins");
					ItemDrop val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
					if ((Object)(object)val3 != (Object)null)
					{
						upgradeTier.Resolved.Add(new UpgradeItem
						{
							Prefab = "Coins",
							Amount = 500,
							Drop = val3
						});
					}
					RuneTrapsPlugin.Log.LogError((object)("Upgrade " + upgradeTier.DisplayName + " ficou sem itens válidos; usando 500 moedas até você corrigir a config."));
				}
			}
		}

		public static RequirementConfig[] BaseRequirements()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			return (RequirementConfig[])(object)new RequirementConfig[4]
			{
				new RequirementConfig("FineWood", 10, 0, true),
				new RequirementConfig("Bronze", 6, 0, true),
				new RequirementConfig("SurtlingCore", 4, 0, true),
				new RequirementConfig("Wood", 0, 0, true)
			};
		}

		private static Recipe FindRecipe()
		{
			//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_00d8: 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_00e7: Expected O, but got Unknown
			if ((Object)(object)_recipe != (Object)null)
			{
				return _recipe;
			}
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			foreach (Recipe recipe in ObjectDB.instance.m_recipes)
			{
				if (!((Object)(object)recipe != (Object)null) || !((Object)(object)recipe.m_item != (Object)null) || !(((Object)recipe.m_item).name == "RuneStaff"))
				{
					continue;
				}
				_recipe = recipe;
				if (recipe.m_resources != null && recipe.m_resources.Length != 0 && recipe.m_resources.Length < 4)
				{
					Requirement[] array = (Requirement[])(object)new Requirement[4];
					Array.Copy(recipe.m_resources, array, recipe.m_resources.Length);
					for (int i = recipe.m_resources.Length; i < 4; i++)
					{
						array[i] = new Requirement
						{
							m_resItem = recipe.m_resources[0].m_resItem,
							m_amount = 0,
							m_amountPerLevel = 0
						};
					}
					recipe.m_resources = array;
				}
				if (recipe.m_resources != null && recipe.m_resources.Length >= 4)
				{
					_baseDrops = (ItemDrop[])(object)new ItemDrop[4];
					for (int j = 0; j < 4; j++)
					{
						_baseDrops[j] = recipe.m_resources[j].m_resItem;
					}
				}
				else
				{
					RuneTrapsPlugin.Log.LogWarning((object)("A receita do cajado tem menos de " + 4 + " requisitos; os itens de upgrade não vão aparecer."));
				}
				break;
			}
			return _recipe;
		}

		private static void Apply(Recipe r, int quality)
		{
			if (_baseDrops == null || r.m_resources == null || r.m_resources.Length < 4)
			{
				return;
			}
			UpgradeTier upgradeTier = null;
			if (quality >= 2 && quality - 2 < Tiers.Length)
			{
				upgradeTier = Tiers[quality - 2];
			}
			for (int i = 0; i < 4; i++)
			{
				if (upgradeTier != null && i < upgradeTier.Resolved.Count)
				{
					r.m_resources[i].m_resItem = upgradeTier.Resolved[i].Drop;
				}
				else
				{
					r.m_resources[i].m_resItem = _baseDrops[i];
				}
			}
			_applied = quality;
			string text = "";
			for (int j = 0; j < 4; j++)
			{
				text = text + (((Object)(object)r.m_resources[j].m_resItem != (Object)null) ? ((Object)r.m_resources[j].m_resItem).name : "?") + " ";
			}
			if (_applyLogs++ < 30)
			{
				RuneTrapsPlugin.Log.LogInfo((object)("Receita do cajado no nível " + quality + ": " + text.Trim()));
			}
		}

		public static void Tick()
		{
			FindRecipe();
		}

		public static void ApplyPatches(Harmony harmony)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			TryPrefixAll(harmony, typeof(InventoryGui), "SetupRequirement");
			TryPrefixAll(harmony, typeof(Player), "HaveRequirements");
			TryPrefixAll(harmony, typeof(Player), "ConsumeResources");
			TryPostfix(harmony, typeof(Requirement), "GetAmount", "GetAmountPostfix");
			TryPostfix(harmony, typeof(Recipe), "GetRequiredStation", "StationPostfix");
			TryPostfix(harmony, typeof(Recipe), "GetRequiredStationLevel", "StationLevelPostfix");
			TryPostfix(harmony, typeof(Player), "GetAvailableRecipes", "AvailablePostfix");
			try
			{
				BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
				int num = 0;
				MethodInfo[] methods = typeof(ItemData).GetMethods(bindingAttr);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!(methodInfo.Name != "GetTooltip") && !(methodInfo.ReturnType != typeof(string)))
					{
						harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(RuneStaffUpgrades), "TooltipPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
				if (num == 0)
				{
					RuneTrapsPlugin.Log.LogWarning((object)"Não achei GetTooltip; a linha 'Potência das runas' não vai aparecer no item.");
				}
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Falha ao aplicar o patch de tooltip: " + ex.Message));
			}
		}

		public static void ApplyFromArgs(object[] __args)
		{
			try
			{
				Recipe val = FindRecipe();
				if ((Object)(object)val == (Object)null || __args == null)
				{
					return;
				}
				bool flag = false;
				int num = -1;
				foreach (object obj in __args)
				{
					if (obj == val)
					{
						flag = true;
						continue;
					}
					if (obj is Requirement[] array && array == val.m_resources)
					{
						flag = true;
						continue;
					}
					Requirement val2 = (Requirement)((obj is Requirement) ? obj : null);
					if (val2 != null && val.m_resources != null && Array.IndexOf(val.m_resources, val2) >= 0)
					{
						flag = true;
					}
					else if (obj is int && num < 0)
					{
						num = (int)obj;
					}
				}
				if (flag && num >= 0)
				{
					num = Mathf.Clamp(num, 1, 7);
					if (num != _applied)
					{
						Apply(val, num);
					}
				}
			}
			catch (Exception ex)
			{
				if (!_tickErrorLogged)
				{
					_tickErrorLogged = true;
					RuneTrapsPlugin.Log.LogWarning((object)("Falha ao trocar os itens da receita do cajado: " + ex.Message));
				}
			}
		}

		private static void TryPrefixAll(Harmony harmony, Type type, string method)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			int num = 0;
			try
			{
				BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
				MethodInfo[] methods = type.GetMethods(bindingAttr);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!(methodInfo.Name != method))
					{
						harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RuneStaffUpgrades), "ApplyFromArgs", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Falha ao aplicar prefix em " + type.Name + "." + method + ": " + ex.Message));
			}
			if (num == 0)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Método " + type.Name + "." + method + " não encontrado; a troca de itens por nível não vai funcionar."));
			}
			else
			{
				RuneTrapsPlugin.Log.LogInfo((object)("Patch aplicado em " + type.Name + "." + method + " (" + num + ")."));
			}
		}

		private static void TryPostfix(Harmony harmony, Type type, string method, string postfix)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					RuneTrapsPlugin.Log.LogWarning((object)("Método " + type.Name + "." + method + " não encontrado; parte do sistema de upgrades não vai funcionar."));
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(RuneStaffUpgrades), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Falha ao aplicar patch em " + type.Name + "." + method + ": " + ex.Message));
			}
		}

		public static void GetAmountPostfix(object __instance, object[] __args, ref int __result)
		{
			if ((Object)(object)_recipe == (Object)null || _recipe.m_resources == null || __args == null || __args.Length == 0)
			{
				return;
			}
			object[] resources = _recipe.m_resources;
			int num = Array.IndexOf(resources, __instance);
			if (num < 0)
			{
				return;
			}
			int num2 = (int)__args[0];
			if (num2 > 1)
			{
				int num3 = num2 - 2;
				if (num3 < 0 || num3 >= Tiers.Length)
				{
					__result = 0;
					return;
				}
				UpgradeTier upgradeTier = Tiers[num3];
				__result = ((num < upgradeTier.Resolved.Count) ? upgradeTier.Resolved[num].Amount : 0);
			}
		}

		private static CraftingStation GetGaldr()
		{
			if ((Object)(object)_galdr != (Object)null)
			{
				return _galdr;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab(CraftingStations.GaldrTable);
			if ((Object)(object)prefab == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
			{
				prefab = ZNetScene.instance.GetPrefab(CraftingStations.GaldrTable);
			}
			if ((Object)(object)prefab != (Object)null)
			{
				_galdr = prefab.GetComponent<CraftingStation>();
			}
			return _galdr;
		}

		private static bool UsesGaldr(int quality)
		{
			int num = quality - 2;
			if (num >= 0 && num < Tiers.Length)
			{
				return Tiers[num].Galdr;
			}
			return false;
		}

		public static void StationPostfix(object __instance, object[] __args, ref CraftingStation __result)
		{
			if (__instance == _recipe && __args != null && __args.Length != 0 && UsesGaldr((int)__args[0]))
			{
				CraftingStation galdr = GetGaldr();
				if ((Object)(object)galdr != (Object)null)
				{
					__result = galdr;
				}
			}
		}

		public static void StationLevelPostfix(object __instance, object[] __args, ref int __result)
		{
			if (__instance == _recipe && __args != null && __args.Length != 0 && UsesGaldr((int)__args[0]))
			{
				__result = Mathf.Max(1, GaldrLevel.Value);
			}
		}

		public static void AvailablePostfix(object[] __args)
		{
			List<Recipe> list = ((__args != null && __args.Length != 0) ? (__args[0] as List<Recipe>) : null);
			if (list == null || (Object)(object)_recipe == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
				CraftingStation galdr = GetGaldr();
				if (!((Object)(object)currentCraftingStation == (Object)null) && !((Object)(object)galdr == (Object)null) && !(currentCraftingStation.m_name != galdr.m_name) && !list.Contains(_recipe) && localPlayer.IsRecipeKnown(_recipe.m_item.m_itemData.m_shared.m_name))
				{
					list.Add(_recipe);
				}
			}
		}

		public static void TooltipPostfix(object[] __args, ref string __result)
		{
			if (__args == null || __args.Length < 2 || __result == null)
			{
				return;
			}
			object obj = __args[0];
			ItemData val = (ItemData)((obj is ItemData) ? obj : null);
			if (val != null && val.m_shared != null && !(val.m_shared.m_name != "$item_runestaff"))
			{
				int num = ((__args[1] is int) ? ((int)__args[1]) : val.m_quality);
				string text = LocalizationManager.Instance.TryTranslate("$item_runestaff_potency");
				if (!__result.Contains(text))
				{
					float num2 = BonusPerLevel.Value * (float)Mathf.Max(0, num - 1) * 100f;
					__result = __result + "\n" + text + ": <color=orange>+" + num2.ToString("0") + "%</color>";
				}
			}
		}

		public static float Potency(int quality)
		{
			return 1f + BonusPerLevel.Value * (float)Mathf.Max(0, quality - 1);
		}
	}
	internal static class RuneStaffVisual
	{
		public const int Levels = 7;

		public static ConfigEntry<bool> GlowEnabled;

		public static Sprite[] Icons = (Sprite[])(object)new Sprite[7];

		private static Texture2D _glowTex;

		public static readonly Color[] LevelColors = (Color[])(object)new Color[7]
		{
			new Color(1f, 0.45f, 0.1f),
			new Color(0.35f, 1f, 0.25f),
			new Color(0.3f, 0.65f, 1f),
			new Color(1f, 0.25f, 0.2f),
			new Color(0.7f, 0.3f, 1f),
			new Color(1f, 0.7f, 0.2f),
			new Color(1f, 0.95f, 0.8f)
		};

		public static void Init(ConfigFile cfg)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			GlowEnabled = cfg.Bind<bool>("5 - Visual", "BrilhoNaMao", true, new ConfigDescription("Mostra um brilho colorido na ponta do cajado quando ele está na mão.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
		}

		public static void LoadIcons()
		{
			//IL_004b: 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)
			for (int i = 0; i < 7; i++)
			{
				try
				{
					Texture2D val = RuneArt.LoadTexture("cajado_icone_" + (i + 1));
					if ((Object)(object)val != (Object)null)
					{
						Icons[i] = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
					}
				}
				catch (Exception ex)
				{
					RuneTrapsPlugin.Log.LogWarning((object)("Ícone do cajado nível " + (i + 1) + ": " + ex.Message));
				}
			}
		}

		public static void ApplyToItem(SharedData shared)
		{
			if (shared != null && (Object)(object)Icons[0] != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { Icons[0] };
			}
		}

		public static void ApplyPatches(Harmony harmony)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(ItemData), "GetIcon", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(RuneStaffVisual), "GetIconPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					RuneTrapsPlugin.Log.LogWarning((object)"ItemData.GetIcon não encontrado; o ícone do cajado não muda com o nível.");
				}
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Patch do ícone falhou: " + ex.Message));
			}
			try
			{
				MethodInfo methodInfo2 = AccessTools.Method(typeof(VisEquipment), "AttachItem", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(RuneStaffVisual), "AttachItemPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					RuneTrapsPlugin.Log.LogWarning((object)"VisEquipment.AttachItem não encontrado; o brilho do cajado não vai aparecer.");
				}
			}
			catch (Exception ex2)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Patch do brilho falhou: " + ex2.Message));
			}
		}

		public static void GetIconPostfix(ItemData __instance, ref Sprite __result)
		{
			if (__instance != null && __instance.m_shared != null && !(__instance.m_shared.m_name != "$item_runestaff"))
			{
				int num = Mathf.Clamp(__instance.m_quality - 1, 0, 6);
				if ((Object)(object)Icons[num] != (Object)null)
				{
					__result = Icons[num];
				}
			}
		}

		public static void AttachItemPostfix(int itemHash, GameObject __result)
		{
			if (!((Object)(object)__result == (Object)null) && GlowEnabled != null && GlowEnabled.Value)
			{
				bool flag = false;
				try
				{
					GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(itemHash) : null);
					flag = (Object)(object)val != (Object)null && ((Object)val).name == "RuneStaff";
				}
				catch (Exception)
				{
				}
				if (flag && (Object)(object)__result.GetComponent<StaffGlow>() == (Object)null)
				{
					__result.AddComponent<StaffGlow>();
				}
			}
		}

		public static Texture2D GlowTexture()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//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)_glowTex != (Object)null)
			{
				return _glowTex;
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Object)val).hideFlags = (HideFlags)32;
			Color32[] array = (Color32[])(object)new Color32[4096];
			float num = 32f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = ((float)j + 0.5f - num) / num;
					float num3 = ((float)i + 0.5f - num) / num;
					float num4 = Mathf.Clamp01(Mathf.Sqrt(num2 * num2 + num3 * num3));
					float num5 = 1f - num4;
					num5 *= num5;
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num5 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply(false, false);
			_glowTex = val;
			return val;
		}
	}
	internal class StaffGlow : MonoBehaviour
	{
		private Humanoid _owner;

		private Light _light;

		private Transform _halo;

		private Material _mat;

		private bool _placed;

		private int _frames;

		private int _quality = 1;

		private void Awake()
		{
			_owner = ((Component)this).GetComponentInParent<Humanoid>();
		}

		private void Place()
		{
			//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_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_008b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00b5: 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: Expected O, but got Unknown
			//IL_0105: 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_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)
			Transform val = ((Component)this).transform.Find("RuneStaffModel");
			Vector3 val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val.TransformPoint(new Vector3(0f, 0.62f, 0f));
			}
			else
			{
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				if (componentsInChildren.Length == 0)
				{
					return;
				}
				Bounds bounds = componentsInChildren[0].bounds;
				Renderer[] array = componentsInChildren;
				foreach (Renderer val3 in array)
				{
					((Bounds)(ref bounds)).Encapsulate(val3.bounds);
				}
				val2 = ((Bounds)(ref bounds)).center;
			}
			Vector3 localPosition = ((Component)this).transform.InverseTransformPoint(val2);
			GameObject val4 = new GameObject("RuneGlowLight");
			val4.transform.SetParent(((Component)this).transform, false);
			val4.transform.localPosition = localPosition;
			_light = val4.AddComponent<Light>();
			_light.type = (LightType)2;
			_light.shadows = (LightShadows)0;
			GameObject val5 = new GameObject("RuneGlowHalo");
			val5.transform.SetParent(((Component)this).transform, false);
			val5.transform.localPosition = localPosition;
			val5.AddComponent<MeshFilter>().sharedMesh = RuneArt.GetQuadMesh();
			MeshRenderer obj = val5.AddComponent<MeshRenderer>();
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			_mat = RuneArt.CreateMaterial();
			_mat.mainTexture = (Texture)(object)RuneStaffVisual.GlowTexture();
			((Renderer)obj).sharedMaterial = _mat;
			_halo = val5.transform;
			_placed = true;
		}

		private void Update()
		{
			//IL_00d8: 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_010d: 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_01ab: 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_01ca: 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_01e1: 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 (!RuneStaffVisual.GlowEnabled.Value)
			{
				if ((Object)(object)_light != (Object)null)
				{
					((Behaviour)_light).enabled = false;
				}
				if ((Object)(object)_halo != (Object)null)
				{
					((Component)_halo).gameObject.SetActive(false);
				}
				return;
			}
			if (!_placed)
			{
				if (++_frames < 3)
				{
					return;
				}
				Place();
				if (!_placed)
				{
					return;
				}
			}
			if ((Object)(object)_owner != (Object)null)
			{
				ItemData currentWeapon = _owner.GetCurrentWeapon();
				if (currentWeapon != null && currentWeapon.m_shared != null && currentWeapon.m_shared.m_name == "$item_runestaff")
				{
					_quality = currentWeapon.m_quality;
				}
			}
			int num = Mathf.Clamp(_quality, 1, 7);
			Color val = RuneStaffVisual.LevelColors[num - 1];
			float num2 = 1f + 0.1f * Mathf.Sin(Time.time * 3f);
			((Behaviour)_light).enabled = true;
			_light.color = val;
			_light.range = (2.5f + 0.4f * (float)num) * num2;
			_light.intensity = 0.5f + 0.15f * (float)num;
			((Component)_halo).gameObject.SetActive(true);
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				_halo.rotation = ((Component)main).transform.rotation;
			}
			float num3 = (0.22f + 0.03f * (float)num) * num2;
			_halo.localScale = new Vector3(num3, num3, num3) / Mathf.Max(0.0001f, ((Component)this).transform.lossyScale.x);
			_mat.color = new Color(val.r, val.g, val.b, 0.3f);
		}
	}
	public class RuneTrap : MonoBehaviour
	{
		public const string KeyBorn = "rt_born";

		public const string KeyMult = "rt_mult";

		public const string KeyKind = "rt_kind";

		public const string KeyFired = "rt_fired";

		public const string KeyCasterUser = "rt_cu";

		public const string KeyCasterId = "rt_ci";

		private const float FlashDuration = 0.7f;

		private ZNetView _nview;

		private Transform _ring;

		private Light _light;

		private Material _mat;

		private RuneKind _kind;

		private bool _kindApplied;

		private bool _fired;

		private float _firedAt;

		private float _scanTimer;

		private float _spin;

		private static bool _dumped;

		private bool _suppressedLate;

		private void Awake()
		{
			//IL_0077: 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_00a5: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			_nview = ((Component)this).GetComponent<ZNetView>();
			_ring = ((Component)this).transform.Find("Ring");
			RemoveColliders();
			SuppressStrayRenderers();
			if ((Object)(object)_ring != (Object)null)
			{
				Renderer component = ((Component)_ring).GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					_mat = component.material;
					_mat.color = new Color(1f, 1f, 1f, 0f);
				}
			}
			if (RuneTrapsPlugin.UseLight != null && RuneTrapsPlugin.UseLight.Value)
			{
				GameObject val = new GameObject("RuneLight");
				val.transform.SetParent(((Component)this).transform, false);
				val.transform.localPosition = new Vector3(0f, 0.6f, 0f);
				_light = val.AddComponent<Light>();
				_light.type = (LightType)2;
				_light.range = 6f;
				_light.intensity = 0f;
				_light.shadows = (LightShadows)0;
			}
		}

		private void RemoveColliders()
		{
			try
			{
				Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
				foreach (Collider val in componentsInChildren)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
				}
				Rigidbody[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody val2 in componentsInChildren2)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Object.Destroy((Object)(object)val2);
					}
				}
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogWarning((object)("Não consegui remover os colisores da runa: " + ex.Message));
			}
		}

		private void SuppressStrayRenderers()
		{
			if (!_dumped)
			{
				Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
				foreach (Transform val in componentsInChildren)
				{
					StringBuilder stringBuilder = new StringBuilder();
					Component[] components = ((Component)val).GetComponents<Component>();
					foreach (Component val2 in components)
					{
						if ((Object)(object)val2 != (Object)null)
						{
							stringBuilder.Append(((object)val2).GetType().Name).Append(' ');
						}
					}
					RuneTrapsPlugin.Log.LogInfo((object)("[diagnóstico] runa: '" + ((Object)val).name + "' -> " + stringBuilder));
				}
			}
			Renderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren2)
			{
				if (!((Object)(object)_ring != (Object)null) || !((Object)(object)((Component)val3).transform == (Object)(object)_ring))
				{
					if (!_dumped)
					{
						RuneTrapsPlugin.Log.LogInfo((object)("[diagnóstico] renderer extra escondido: '" + ((Object)((Component)val3).gameObject).name + "' (" + ((object)val3).GetType().Name + ")"));
					}
					val3.enabled = false;
				}
			}
			_dumped = true;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_mat != (Object)null)
			{
				Object.Destroy((Object)(object)_mat);
			}
		}

		private void Update()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return;
			}
			ZDO zDO = _nview.GetZDO();
			if (zDO == null)
			{
				return;
			}
			if (!_kindApplied)
			{
				int num = zDO.GetInt("rt_kind", -1);
				if (num < 0)
				{
					return;
				}
				_kind = RuneKinds.Get(num);
				if (_kind == null)
				{
					return;
				}
				if ((Object)(object)_mat != (Object)null)
				{
					_mat.mainTexture = (Texture)(object)_kind.Texture;
				}
				if ((Object)(object)_light != (Object)null)
				{
					_light.color = _kind.LightColor;
				}
				_kindApplied = true;
				if (!_suppressedLate)
				{
					_suppressedLate = true;
					RemoveColliders();
					SuppressStrayRenderers();
				}
			}
			float age = GetAge(zDO);
			if (!_fired && zDO.GetInt("rt_fired", 0) == 1)
			{
				_fired = true;
				_firedAt = Time.time;
			}
			Animate(age);
			if (!_nview.IsOwner())
			{
				return;
			}
			if (_fired)
			{
				if (Time.time - _firedAt > 0.7f)
				{
					ZNetScene.instance.Destroy(((Component)this).gameObject);
				}
			}
			else if (age > RuneTrapsPlugin.Lifetime.Value)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			else
			{
				if (age < RuneTrapsPlugin.ArmDelay.Value)
				{
					return;
				}
				_scanTimer -= Time.deltaTime;
				if (!(_scanTimer > 0f))
				{
					_scanTimer = 0.1f;
					if (HasEnemyInTriggerRadius())
					{
						Detonate(zDO);
					}
				}
			}
		}

		private static float GetAge(ZDO zdo)
		{
			long num = zdo.GetLong("rt_born", 0L);
			if (num == 0L || (Object)(object)ZNet.instance == (Object)null)
			{
				return 0f;
			}
			return (float)(ZNet.instance.GetTime() - new DateTime(num)).TotalSeconds;
		}

		private static bool IsTriggerTarget(Character c)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)c == (Object)null || c.IsDead() || c.IsPlayer() || c.IsTamed())
			{
				return false;
			}
			if ((int)c.GetFaction() == 0)
			{
				return false;
			}
			return (Object)(object)((Component)c).GetComponent<MonsterAI>() != (Object)null;
		}

		private static bool IsDamageTarget(Character c)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			if ((Object)(object)c == (Object)null || c.IsDead() || c.IsPlayer() || c.IsTamed())
			{
				return false;
			}
			return (int)c.GetFaction() > 0;
		}

		private bool HasEnemyInTriggerRadius()
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_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)
			Vector3 position = ((Component)this).transform.position;
			float value = RuneTrapsPlugin.TriggerRadius.Value;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (IsTriggerTarget(allCharacter))
				{
					Vector3 position2 = ((Component)allCharacter).transform.position;
					float num = position2.x - position.x;
					float num2 = position2.z - position.z;
					if (Mathf.Sqrt(num * num + num2 * num2) <= value + allCharacter.GetRadius() * 0.5f && Mathf.Abs(position2.y - position.y) < 2.5f)
					{
						return true;
					}
				}
			}
			return false;
		}

		private void Detonate(ZDO zdo)
		{
			//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_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_00bb: Expected O, but got Unknown
			//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_015a: 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_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_0166: 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_0180: 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_01ae: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			zdo.Set("rt_fired", 1);
			_fired = true;
			_firedAt = Time.time;
			float num = zdo.GetFloat("rt_mult", 1f);
			ZDOID attacker = default(ZDOID);
			((ZDOID)(ref attacker))..ctor(zdo.GetLong("rt_cu", 0L), (uint)zdo.GetLong("rt_ci", 0L));
			Vector3 position = ((Component)this).transform.position;
			float value = _kind.Radius.Value;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (IsDamageTarget(allCharacter) && !(Vector3.Distance(((Component)allCharacter).transform.position, position) > value + allCharacter.GetRadius()))
				{
					HitData val = new HitData();
					val.m_damage.m_fire = _kind.Fire.Value * num;
					val.m_damage.m_frost = _kind.Frost.Value * num;
					val.m_damage.m_lightning = _kind.Lightning.Value * num;
					val.m_damage.m_poison = _kind.Poison.Value * num;
					val.m_damage.m_blunt = _kind.Blunt.Value * num;
					Vector3 centerPoint = allCharacter.GetCenterPoint();
					Vector3 val2 = centerPoint - position;
					val2.y = Mathf.Max(val2.y, 0.3f);
					val.m_point = centerPoint;
					val.m_dir = ((Vector3)(ref val2)).normalized;
					val.m_pushForce = _kind.Push.Value;
					val.m_skill = (SkillType)9;
					val.m_attacker = attacker;
					val.m_blockable = false;
					val.m_dodgeable = false;
					allCharacter.Damage(val);
				}
			}
		}

		private void Animate(float age)
		{
			//IL_01d6: 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_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_0196: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0.01f, RuneTrapsPlugin.ArmDelay.Value);
			float num2 = RuneTrapsPlugin.TriggerRadius.Value * 2.2f;
			float num5;
			float num6;
			if (_fired)
			{
				float num3 = Mathf.Clamp01((Time.time - _firedAt) / 0.7f);
				float num4 = 1f - (1f - num3) * (1f - num3);
				num2 = Mathf.Lerp(num2, _kind.Radius.Value * 2f, num4);
				num5 = 1f - num3;
				num6 = Mathf.Lerp(6f, 0f, num3);
			}
			else
			{
				bool num7 = age >= num;
				num5 = (num7 ? 0.95f : Mathf.Lerp(0.15f, 0.95f, Mathf.Clamp01(age / num)));
				num6 = (num7 ? (1.2f + 0.3f * Mathf.Sin(Time.time * 4f)) : 0.4f);
				float num8 = RuneTrapsPlugin.Lifetime.Value - age;
				if (num8 < 3f)
				{
					float num9 = Mathf.Clamp01(num8 / 3f);
					num5 *= num9;
					num6 *= num9;
				}
			}
			if ((Object)(object)_ring != (Object)null)
			{
				_spin += Time.deltaTime * (_fired ? 240f : 12f);
				_ring.localRotation = Quaternion.Euler(90f, 0f, 0f) * Quaternion.Euler(0f, 0f, _spin);
				_ring.localScale = new Vector3(num2, num2, 1f);
			}
			if ((Object)(object)_mat != (Object)null && _mat.HasProperty("_Color"))
			{
				_mat.color = new Color(1f, 1f, 1f, num5);
			}
			if ((Object)(object)_light != (Object)null)
			{
				_light.intensity = Mathf.Max(0f, num6);
			}
		}
	}
	internal class ConfigurationManagerAttributes
	{
		public bool IsAdminOnly = true;
	}
	[BepInPlugin("mateu.valheim.runetraps", "RuneTraps", "0.4.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class RuneTrapsPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "mateu.valheim.runetraps";

		public const string PluginName = "RuneTraps";

		public const string PluginVersion = "0.4.1";

		public const string StaffPrefabName = "RuneStaff";

		public const string StaffToken = "$item_runestaff";

		public const string RunePrefabName = "RuneTrap";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<int> MaxRunes;

		internal static ConfigEntry<float> Lifetime;

		internal static ConfigEntry<float> ArmDelay;

		internal static ConfigEntry<float> TriggerRadius;

		internal static ConfigEntry<float> EitrCost;

		internal static ConfigEntry<KeyCode> SelectKey;

		internal static ConfigEntry<int> SelectedKind;

		internal static ConfigEntry<bool> UseLight;

		private static bool _tickLogged;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Range = BindAdmin("1 - Magia", "Alcance", 20f, "Distância máxima (m) em que a runa pode ser colocada.");
			MaxRunes = BindAdmin("1 - Magia", "RunasSimultaneas", 3, "Quantas runas suas podem existir ao mesmo tempo. A mais antiga some quando passa do limite.");
			Lifetime = BindAdmin("1 - Magia", "DuracaoSegundos", 60f, "Quanto tempo a runa dura antes de se apagar.");
			ArmDelay = BindAdmin("1 - Magia", "TempoParaArmar", 1f, "Segundos até a runa ficar ativa depois de criada.");
			TriggerRadius = BindAdmin("1 - Magia", "RaioDeAtivacao", 2.5f, "Raio (m) em que um inimigo ativa a runa.");
			EitrCost = BindAdmin("1 - Magia", "CustoDeEitr", 10f, "Eitr gasto a cada runa criada.");
			RuneKinds.Init(((BaseUnityPlugin)this).Config);
			SelectKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("3 - Controles", "TeclaTrocarRuna", (KeyCode)118, "Com o Cajado de Runas equipado, esta tecla troca o tipo de runa (fogo, gelo, raio, veneno, explosiva).");
			SelectedKind = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Controles", "RunaSelecionada", 0, "Runa atualmente selecionada (0 = fogo, 1 = gelo, 2 = raio, 3 = veneno, 4 = explosiva).");
			UseLight = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Controles", "UsarLuzNaRuna", false, "Liga uma luz colorida sobre cada runa. Desligada por padrão por causa de um bug visual; teste por sua conta.");
			RuneStaffUpgrades.Init(((BaseUnityPlugin)this).Config);
			RuneStaffVisual.Init(((BaseUnityPlugin)this).Config);
			RuneStaffModel.Init(((BaseUnityPlugin)this).Config);
			AddLocalization();
			ApplyPatches();
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new ItemSearchCommand());
			PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
		}

		private ConfigEntry<T> BindAdmin<T>(string section, string key, T defaultValue, string description)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes()
			}));
		}

		private void Update()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				RuneStaffUpgrades.Tick();
			}
			catch (Exception ex)
			{
				if (!_tickLogged)
				{
					_tickLogged = true;
					Log.LogWarning((object)("Erro no sistema de upgrades: " + ex.Message));
				}
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && Input.GetKeyDown(SelectKey.Value) && !InputBlocked())
			{
				ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
				if (currentWeapon != null && currentWeapon.m_shared != null && !(currentWeapon.m_shared.m_name != "$item_runestaff"))
				{
					int num = RuneKinds.All.Length;
					SelectedKind.Value = (SelectedKind.Value + 1) % num;
					RuneKind runeKind = RuneKinds.Get(SelectedKind.Value);
					string text = LocalizationManager.Instance.TryTranslate("$rune_selected") + ": " + LocalizationManager.Instance.TryTranslate(runeKind.Token);
					((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
				}
			}
		}

		private static bool InputBlocked()
		{
			try
			{
				if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
				{
					return true;
				}
				if (Console.IsVisible())
				{
					return true;
				}
				if (InventoryGui.IsVisible())
				{
					return true;
				}
				if (Menu.IsVisible())
				{
					return true;
				}
				if (TextInput.IsVisible())
				{
					return true;
				}
			}
			catch (Exception)
			{
			}
			return false;
		}

		private void OnVanillaPrefabsAvailable()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
			try
			{
				RuneArt.LoadAll();
				RuneStaffVisual.LoadIcons();
				CreateRunePrefab();
				RuneStaffUpgrades.Resolve();
				CreateStaff();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Falha ao registrar a runa/cajado: " + ex));
			}
		}

		private void CreateRunePrefab()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_004f: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateEmptyPrefab("RuneTrap", true);
			val.GetComponent<ZNetView>().m_persistent = false;
			GameObject val2 = new GameObject("Ring");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			val2.transform.localPosition = new Vector3(0f, 0.03f, 0f);
			val2.AddComponent<MeshFilter>().sharedMesh = RuneArt.GetQuadMesh();
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			((Renderer)obj).sharedMaterial = RuneArt.CreateMaterial();
			Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			MeshRenderer[] componentsInChildren2 = val.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val3 in componentsInChildren2)
			{
				if ((Object)(object)((Component)val3).transform != (Object)(object)val2.transform)
				{
					Object.DestroyImmediate((Object)(object)val3);
				}
			}
			MeshFilter[] componentsInChildren3 = val.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val4 in componentsInChildren3)
			{
				if ((Object)(object)((Component)val4).transform != (Object)(object)val2.transform)
				{
					Object.DestroyImmediate((Object)(object)val4);
				}
			}
			SetLayerRecursive(val, 2);
			val.AddComponent<RuneTrap>();
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, false));
			Log.LogInfo((object)"Prefab da runa registrado.");
		}

		private static void SetLayerRecursive(GameObject go, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			go.layer = layer;
			foreach (Transform item in go.transform)
			{
				SetLayerRecursive(((Component)item).gameObject, layer);
			}
		}

		private void CreateStaff()
		{
			//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_0078: 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_008e: 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: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//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)
			string[] obj = new string[3] { "StaffFireball", "StaffIceShards", "StaffShield" };
			string text = null;
			string[] array = obj;
			foreach (string text2 in array)
			{
				if ((Object)(object)PrefabManager.Instance.GetPrefab(text2) != (Object)null)
				{
					text = text2;
					break;
				}
			}
			if (text == null)
			{
				Log.LogError((object)"Nenhum cajado base encontrado. O item não foi criado.");
				return;
			}
			ItemConfig val = new ItemConfig
			{
				Name = "$item_runestaff",
				Description = "$item_runestaff_desc",
				CraftingStation = CraftingStations.Forge,
				MinStationLevel = 1,
				Requirements = RuneStaffUpgrades.BaseRequirements()
			};
			CustomItem val2 = new CustomItem("RuneStaff", text, val);
			SharedData shared = val2.ItemDrop.m_itemData.m_shared;
			if (shared != null)
			{
				if (shared.m_attack != null)
				{
					shared.m_attack.m_attackEitr = EitrCost.Value;
					shared.m_attack.m_attackStamina = 0f;
					shared.m_attack.m_attackHealth = 0f;
				}
				else
				{
					Log.LogWarning((object)"Não consegui definir o custo de eitr do cajado.");
				}
				RuneStaffVisual.ApplyToItem(shared);
				shared.m_maxQuality = 7;
				shared.m_damages = default(DamageTypes);
				shared.m_damagesPerLevel = default(DamageTypes);
				shared.m_durabilityPerLevel = 0f;
				shared.m_armorPerLevel = 0f;
				shared.m_blockPowerPerLevel = 0f;
				shared.m_deflectionForcePerLevel = 0f;
			}
			RuneStaffModel.Apply(val2.ItemPrefab);
			ItemManager.Instance.AddItem(val2);
			Log.LogInfo((object)("Cajado de Runas registrado (base: " + text + ")."));
		}

		private void AddLocalization()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_runestaff", "Staff of Runes" },
				{ "item_runestaff_desc", "Traces an elemental rune on the ground. When an enemy steps on it, it detonates. Press the swap key (default V) while holding it to change rune type. Each biome upgrade (Swamp to Deep North) adds 25% rune potency." },
				{ "item_runestaff_potency", "Rune potency" },
				{ "rune_selected", "Rune" },
				{ "rune_fire", "Fire Rune" },
				{ "rune_frost", "Frost Rune" },
				{ "rune_lightning", "Lightning Rune" },
				{ "rune_poison", "Poison Rune" },
				{ "rune_explosive", "Explosive Rune" }
			});
			text = "Portuguese_Brazilian";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_runestaff", "Cajado de Runas" },
				{ "item_runestaff_desc", "Traça uma runa elemental no chão. Quando um inimigo pisa nela, ela detona. Com o cajado na mão, aperte a tecla de troca (padrão V) para mudar o tipo de runa. Cada upgrade de bioma (do Pântano ao Extremo Norte) soma 25% de potência às runas." },
				{ "item_runestaff_potency", "Potência das runas" },
				{ "rune_selected", "Runa" },
				{ "rune_fire", "Runa de Fogo" },
				{ "rune_frost", "Runa de Gelo" },
				{ "rune_lightning", "Runa de Raio" },
				{ "rune_poison", "Runa de Veneno" },
				{ "rune_explosive", "Runa Explosiva" }
			});
		}

		private void ApplyPatches()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			Harmony val = new Harmony("mateu.valheim.runetraps");
			MethodInfo methodInfo = AccessTools.Method(typeof(Attack), "ProjectileAttackTriggered", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				methodInfo = AccessTools.Method(typeof(Attack), "FireProjectileBurst", (Type[])null, (Type[])null);
			}
			if (methodInfo == null)
			{
				Log.LogError((object)"Não achei o método de disparo de projétil em Attack. O cajado vai atirar o projétil normal.");
			}
			else
			{
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(AttackPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("Patch aplicado em Attack." + methodInfo.Name));
			}
			RuneStaffUpgrades.ApplyPatches(val);
			RuneStaffVisual.ApplyPatches(val);
		}
	}
	internal class ItemSearchCommand : ConsoleCommand
	{
		public override string Name => "runetraps_itens";

		public override string Help => "Procura nomes internos de itens para a config de upgrades. Ex.: runetraps_itens gold";

		public override void Run(string[] args)
		{
			if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)Console.instance == (Object)null)
			{
				return;
			}
			string text = ((args != null && args.Length != 0) ? args[0].ToLowerInvariant() : "");
			int num = 0;
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				if (!((Object)(object)item == (Object)null) && (text.Length <= 0 || ((Object)item).name.ToLowerInvariant().Contains(text)))
				{
					Console.instance.Print(((Object)item).name);
					if (++num >= 40)
					{
						Console.instance.Print("... (mostrando só os 40 primeiros; refine a busca)");
						break;
					}
				}
			}
			if (num == 0)
			{
				Console.instance.Print("Nenhum item encontrado.");
			}
		}
	}
	internal static class AttackPatch
	{
		private static bool _warned;

		public static bool Prefix(Attack __instance)
		{
			try
			{
				Traverse val = Traverse.Create((object)__instance);
				ItemData value = val.Field("m_weapon").GetValue<ItemData>();
				if (value == null || value.m_shared == null)
				{
					return true;
				}
				if (value.m_shared.m_name != "$item_runestaff")
				{
					return true;
				}
				Humanoid value2 = val.Field("m_character").GetValue<Humanoid>();
				if ((Object)(object)value2 == (Object)null)
				{
					if (!_warned)
					{
						_warned = true;
						RuneTrapsPlugin.Log.LogWarning((object)"Campo m_character não encontrado em Attack.");
					}
					return true;
				}
				RuneSpell.PlaceRune(value2, value);
				return false;
			}
			catch (Exception ex)
			{
				RuneTrapsPlugin.Log.LogError((object)("Erro no patch de ataque: " + ex));
				return true;
			}
		}
	}
	internal static class RuneSpell
	{
		private static readonly List<GameObject> ActiveRunes = new List<GameObject>();

		public static void PlaceRune(Humanoid caster, ItemData weapon)
		{
			//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_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_00b3: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c4: 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_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)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00fe: 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_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)
			//IL_0114: 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_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_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_0150: 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_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_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: 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_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("RuneTrap");
			if ((Object)(object)prefab == (Object)null)
			{
				RuneTrapsPlugin.Log.LogError((object)"Prefab da runa não encontrado no ZNetScene.");
				return;
			}
			RuneKind runeKind = RuneKinds.Get(RuneTrapsPlugin.SelectedKind.Value);
			Vector3 eyePoint = ((Character)caster).GetEyePoint();
			Vector3 lookDir = ((Character)caster).GetLookDir();
			int mask = LayerMask.GetMask(new string[7] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "vehicle" });
			float value = RuneTrapsPlugin.Range.Value;
			RaycastHit val2 = default(RaycastHit);
			Vector3 val = ((!Physics.Raycast(eyePoint, lookDir, ref val2, value, mask)) ? (eyePoint + lookDir * value) : (((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.2f));
			Vector3 val3 = val;
			Vector3 val4 = Vector3.up;
			if (Physics.Raycast(val + Vector3.up * 1.5f, Vector3.down, ref val2, 8f, mask))
			{
				val3 = ((RaycastHit)(ref val2)).point;
				val4 = ((RaycastHit)(ref val2)).normal;
			}
			else
			{
				val3.y = ZoneSystem.instance.GetGroundHeight(val3);
			}
			if (val4.y < 0.7f)
			{
				val4 = Vector3.up;
			}
			ActiveRunes.RemoveAll((GameObject r) => (Object)(object)r == (Object)null);
			while (ActiveRunes.Count >= Mathf.Max(1, RuneTrapsPlugin.MaxRunes.Value))
			{
				GameObject val5 = ActiveRunes[0];
				ActiveRunes.RemoveAt(0);
				if ((Object)(object)val5 != (Object)null)
				{
					ZNetView component = val5.GetComponent<ZNetView>();
					if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
					{
						ZNetScene.instance.Destroy(val5);
					}
				}
			}
			GameObject val6 = Object.Instantiate<GameObject>(prefab, val3 + val4 * 0.02f, Quaternion.FromToRotation(Vector3.up, val4));
			ZNetView component2 = val6.GetComponent<ZNetView>();
			ZDO val7 = (((Object)(object)component2 != (Object)null) ? component2.GetZDO() : null);
			if (val7 != null)
			{
				float skillFactor = ((Character)caster).GetSkillFactor((SkillType)9);
				float num = Mathf.Lerp(0.6f, 1.5f, skillFactor);
				int quality = ((weapon == null) ? 1 : Mathf.Max(1, weapon.m_quality));
				float num2 = num * RuneStaffUpgrades.Potency(quality);
				ZDOID zDOID = ((Character)caster).GetZDOID();
				val7.Set("rt_born", ZNet.instance.GetTime().Ticks);
				val7.Set("rt_mult", num2);
				val7.Set("rt_kind", runeKind.Index);
				val7.Set("rt_cu", ((ZDOID)(ref zDOID)).UserID);
				val7.Set("rt_ci", (long)((ZDOID)(ref zDOID)).ID);
			}
			ActiveRunes.Add(val6);
			((Character)caster).RaiseSkill((SkillType)9, 0.5f);
		}
	}
}