Decompiled source of Arantel RPG v1.3.0

patchers/ArantelPreloader.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using BepInEx.Logging;
using Mono.Cecil;

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

public static class Preloader
{
	private sealed class SplashLog : ILogListener, IDisposable
	{
		private readonly Process child;

		private volatile bool closed;

		private string pending;

		private static readonly char[] NewLine = new char[2] { '\r', '\n' };

		public SplashLog(Process child)
		{
			this.child = child;
		}

		public void LogEvent(object sender, LogEventArgs entry)
		{
			if (!closed && entry.Data != null)
			{
				string text = ((object)entry).ToString().TrimEnd();
				int num = text.IndexOfAny(NewLine);
				if (num >= 0)
				{
					text = text.Substring(0, num);
				}
				if (text.Length > 512)
				{
					text = text.Substring(0, 511) + "…";
				}
				Interlocked.Exchange(ref pending, text);
			}
		}

		public void WriteLines()
		{
			try
			{
				using StreamWriter streamWriter = new StreamWriter(child.StandardInput.BaseStream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
				while (!closed && !child.HasExited)
				{
					string text = Interlocked.Exchange(ref pending, null);
					if (text != null)
					{
						streamWriter.WriteLine(text);
						streamWriter.Flush();
					}
					Thread.Sleep(100);
				}
			}
			catch (IOException)
			{
			}
			finally
			{
				Dispose();
				child.Dispose();
			}
		}

		public void Dispose()
		{
			closed = true;
			Interlocked.Exchange(ref pending, null);
		}
	}

	public static IEnumerable<string> TargetDLLs => new string[0];

	public static void Patch(AssemblyDefinition unused)
	{
	}

	public static void Initialize()
	{
		using Process process = Process.GetCurrentProcess();
		if (Environment.OSVersion.Platform != PlatformID.Win32NT || !string.Equals(process.ProcessName, "valheim", StringComparison.OrdinalIgnoreCase) || Array.Exists(Environment.GetCommandLineArgs(), (string s) => s.Equals("-batchmode", StringComparison.OrdinalIgnoreCase)))
		{
			return;
		}
		string text = Path.Combine(Path.GetDirectoryName(typeof(Preloader).Assembly.Location), "ArantelSplash.exe");
		if (!File.Exists(text))
		{
			return;
		}
		try
		{
			ProcessStartInfo processStartInfo = new ProcessStartInfo(text, process.Id.ToString());
			processStartInfo.UseShellExecute = false;
			processStartInfo.RedirectStandardInput = true;
			processStartInfo.CreateNoWindow = true;
			ProcessStartInfo startInfo = processStartInfo;
			Process child = Process.Start(startInfo);
			SplashLog splashLog = new SplashLog(child);
			Logger.Listeners.Add((ILogListener)(object)splashLog);
			Thread thread = new Thread(splashLog.WriteLines);
			thread.IsBackground = true;
			thread.Name = "Arantel Splash";
			thread.Start();
		}
		catch (Exception ex)
		{
			Logger.CreateLogSource("Arantel Splash").LogWarning((object)ex.Message);
		}
	}
}

patchers/ArantelSplash.exe

Decompiled 4 days ago
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

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

internal sealed class Splash : Form
{
	private readonly Process game;

	private readonly EventWaitHandle ready;

	private readonly Stopwatch elapsed;

	private readonly Timer timer;

	private readonly Bitmap logo;

	private volatile string status;

	private static readonly Color Brass = Color.FromArgb(220, 193, 138);

	private static readonly Color Forest = Color.FromArgb(21, 40, 35);

	protected override bool ShowWithoutActivation => true;

	protected override CreateParams CreateParams
	{
		get
		{
			CreateParams createParams = ((Form)this).CreateParams;
			createParams.ExStyle |= 0x8000000;
			return createParams;
		}
	}

	[DllImport("user32.dll")]
	private static extern IntPtr GetForegroundWindow();

	[DllImport("user32.dll")]
	private static extern uint GetWindowThreadProcessId(IntPtr window, out uint pid);

	private Splash(Process owner, EventWaitHandle signal)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Expected O, but got Unknown
		MouseEventHandler val = null;
		KeyEventHandler val2 = null;
		elapsed = Stopwatch.StartNew();
		timer = new Timer();
		status = "Iniciando BepInEx…";
		((Form)this)..ctor();
		game = owner;
		ready = signal;
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("fjord.jpg"))
		{
			Image val3 = Image.FromStream(stream);
			try
			{
				logo = new Bitmap(val3);
			}
			finally
			{
				((IDisposable)val3)?.Dispose();
			}
		}
		((Control)this).Text = "Arantel MMO";
		((Control)this).BackColor = Forest;
		((Form)this).ClientSize = new Size(768, 432);
		((Form)this).FormBorderStyle = (FormBorderStyle)0;
		((Form)this).StartPosition = (FormStartPosition)1;
		((Control)this).DoubleBuffered = true;
		Thread thread = new Thread(ReadLog);
		thread.IsBackground = true;
		thread.Start();
		timer.Interval = 33;
		timer.Tick += delegate
		{
			if (game.HasExited || ready.WaitOne(0) || elapsed.Elapsed.TotalMinutes > 10.0)
			{
				((Form)this).Close();
			}
			else
			{
				GetWindowThreadProcessId(GetForegroundWindow(), out var pid);
				bool flag = pid == game.Id;
				if (((Form)this).TopMost != flag)
				{
					((Form)this).TopMost = flag;
				}
				((Control)this).Invalidate();
			}
		};
		timer.Start();
		if (val == null)
		{
			val = (MouseEventHandler)delegate
			{
				((Form)this).Close();
			};
		}
		((Control)this).MouseClick += val;
		if (val2 == null)
		{
			val2 = (KeyEventHandler)delegate(object s, KeyEventArgs e)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				if ((int)e.KeyCode == 27)
				{
					((Form)this).Close();
				}
			};
		}
		((Control)this).KeyDown += val2;
	}

	private void ReadLog()
	{
		try
		{
			using StreamReader streamReader = new StreamReader(Console.OpenStandardInput(), Encoding.UTF8);
			string value;
			while ((value = streamReader.ReadLine()) != null)
			{
				if (!string.IsNullOrWhiteSpace(value))
				{
					status = value;
				}
			}
		}
		catch (IOException)
		{
		}
	}

	protected override void OnPaint(PaintEventArgs e)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Expected O, but got Unknown
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Expected O, but got Unknown
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Expected O, but got Unknown
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Expected O, but got Unknown
		Graphics graphics = e.Graphics;
		graphics.SmoothingMode = (SmoothingMode)4;
		double totalSeconds = elapsed.Elapsed.TotalSeconds;
		int width = ((Form)this).ClientSize.Width;
		int height = ((Form)this).ClientSize.Height;
		float num = 1.02f + 0.018f * (float)Math.Sin(totalSeconds * 0.23);
		int num2 = (int)((float)width * num);
		int num3 = (int)((float)height * num);
		graphics.InterpolationMode = (InterpolationMode)7;
		graphics.DrawImage((Image)(object)logo, (width - num2) / 2, (height - num3) / 2, num2, num3);
		Rectangle rectangle = new Rectangle(0, height / 2, width, height - height / 2);
		LinearGradientBrush val = new LinearGradientBrush(rectangle, Color.Transparent, Color.FromArgb(226, 4, 14, 19), 90f);
		try
		{
			graphics.FillRectangle((Brush)(object)val, rectangle);
		}
		finally
		{
			((IDisposable)val)?.Dispose();
		}
		for (int i = 0; i < 24; i++)
		{
			float num4 = (float)(((double)(i * 131) + 9.0 * Math.Sin(totalSeconds * 0.4 + (double)i)) % (double)width);
			float num5 = (float)height - (float)(((double)(i * 47) + totalSeconds * (double)(3 + i % 4)) % (double)height);
			int alpha = 45 + (int)(54.0 * (0.5 + 0.5 * Math.Sin(totalSeconds + (double)i)));
			SolidBrush val2 = new SolidBrush(Color.FromArgb(alpha, 230, 213, 159));
			try
			{
				graphics.FillEllipse((Brush)(object)val2, num4, num5, 2f, 2f);
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}
		Font val3 = new Font("Georgia", 33f, (FontStyle)0);
		try
		{
			Font val4 = new Font("Segoe UI", 10f);
			try
			{
				SolidBrush val5 = new SolidBrush(Color.FromArgb(94, 180, 159, 105));
				try
				{
					SolidBrush val6 = new SolidBrush(Brass);
					try
					{
						TextRenderer.DrawText((IDeviceContext)(object)graphics, "A R A N T E L", val3, new Rectangle(0, 263, width, 76), Brass, (TextFormatFlags)5);
						graphics.FillRectangle((Brush)(object)val5, width / 2 - 114, 359, 228, 2);
						float num6 = (float)(width / 2 - 114) + (float)((1.0 - Math.Cos(totalSeconds * 1.35)) * 0.5) * 184f;
						graphics.FillRectangle((Brush)(object)val6, num6, 359f, 44f, 2f);
						TextRenderer.DrawText((IDeviceContext)(object)graphics, status, val4, new Rectangle(26, 372, width - 52, 29), Color.Gainsboro, (TextFormatFlags)34853);
					}
					finally
					{
						((IDisposable)val6)?.Dispose();
					}
				}
				finally
				{
					((IDisposable)val5)?.Dispose();
				}
			}
			finally
			{
				((IDisposable)val4)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)val3)?.Dispose();
		}
		((Form)this).OnPaint(e);
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing)
		{
			((Component)(object)timer).Dispose();
			((Image)logo).Dispose();
		}
		((Form)this).Dispose(disposing);
	}

	[STAThread]
	private static void Main(string[] args)
	{
		if (args.Length != 1 || !int.TryParse(args[0], out var result))
		{
			return;
		}
		try
		{
			using Process owner = Process.GetProcessById(result);
			using EventWaitHandle signal = new EventWaitHandle(initialState: false, EventResetMode.ManualReset, "Local\\ArantelReady-" + result);
			Application.EnableVisualStyles();
			Splash splash = new Splash(owner, signal);
			try
			{
				Application.Run((Form)(object)splash);
			}
			finally
			{
				((IDisposable)(object)splash)?.Dispose();
			}
		}
		catch (ArgumentException)
		{
		}
	}
}

plugins/ArantelRPG.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

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

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("br.arantel.rpg", "Arantel RPG", "1.3.0")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	private static class Connections
	{
		private static void Postfix(ZNet __instance, ZNetPeer peer)
		{
			if (__instance.IsServer())
			{
				float nextRequest = 0f;
				float nextTraining = 0f;
				peer.m_rpc.Register<int, int>("br.arantel.rpg.pedido.v3", (Action<ZRpc, int, int>)delegate(ZRpc rpc, int branch, int target)
				{
					//IL_0068: Unknown result type (might be due to invalid IL or missing references)
					bool flag = branch >= 1000;
					float realtimeSinceStartup = Time.realtimeSinceStartup;
					if (peer.IsReady() && !(realtimeSinceStartup < (flag ? nextTraining : nextRequest)))
					{
						if (flag)
						{
							nextTraining = realtimeSinceStartup + 2f;
						}
						else
						{
							nextRequest = realtimeSinceStartup + 0.12f;
						}
						ZDO zDO = ZDOMan.instance.GetZDO(peer.m_characterID);
						long num = peer.m_playerID;
						if (num == 0 && zDO != null && zDO.GetOwner() == peer.m_uid)
						{
							num = zDO.GetLong(ZDOVars.s_playerID, 0L);
						}
						string hostName = peer.m_socket.GetHostName();
						if (num != 0 && !string.IsNullOrEmpty(hostName) && !(hostName == "0"))
						{
							string text = Current.Handle(hostName, num, branch, target);
							rpc.Invoke(flag ? "br.arantel.rpg.treino.v3" : "br.arantel.rpg.ficha.v3", new object[2] { num, text });
						}
					}
				});
				return;
			}
			peer.m_rpc.Register<long, string>("br.arantel.rpg.ficha.v3", (Action<ZRpc, long, string>)delegate(ZRpc rpc, long id, string encoded)
			{
				if ((Object)(object)ZNet.instance == (Object)(object)__instance && rpc == __instance.GetServerRPC() && id == Current.character)
				{
					Current.Receive(encoded);
				}
			});
			peer.m_rpc.Register<long, string>("br.arantel.rpg.treino.v3", (Action<ZRpc, long, string>)delegate(ZRpc rpc, long id, string encoded)
			{
				if ((Object)(object)ZNet.instance == (Object)(object)__instance && rpc == __instance.GetServerRPC() && id == Current.character)
				{
					Current.ReceivePractice(encoded);
				}
			});
		}
	}

	[HarmonyPatch(typeof(Skills), "RaiseSkill")]
	private static class ClassPractice
	{
		private static void Postfix(Player ___m_player, SkillType skillType, float factor)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected I4, but got Unknown
			Progression progression = For(___m_player);
			if (progression == null || !(factor > 0f) || !Progression.TrainsClass(progression.Role, skillType) || progression.Level == 11 || ((Character)___m_player).IsDead() || Current.pending)
			{
				return;
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup < Current.nextPractice)
			{
				return;
			}
			Current.nextPractice = realtimeSinceStartup + 2f + 0.1f;
			int num = 1000 + skillType;
			if (Current.session.IsServer())
			{
				Current.ReceivePractice(Current.Handle("local", Current.character, num, progression.Experience));
				return;
			}
			ZRpc serverRPC = Current.session.GetServerRPC();
			if (serverRPC != null)
			{
				serverRPC.Invoke("br.arantel.rpg.pedido.v3", new object[2] { num, progression.Experience });
			}
		}
	}

	[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
	private static class Vitals
	{
		private static void Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr)
		{
			Progression progression = For(__instance);
			if (progression != null)
			{
				hp += ((progression.Role == 1) ? 20 : 0) + 5 * progression.Ranks[0] + 12 * progression.Ranks[12];
				stamina += ((progression.Role == 3) ? 20 : 0) + 5 * progression.Ranks[2] + 12 * progression.Ranks[14];
				eitr += ((progression.Role == 2) ? 32 : 0) + 5 * progression.Ranks[3] + 14 * progression.Ranks[15];
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyStealth")]
	private static class Stealth
	{
		private static void Postfix(Character ___m_character, ref float stealth)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				stealth *= 1f - 0.08f * (float)progression.Ranks[1] - ((progression.Role == 4) ? 0.22f : 0f) - 0.12f * (float)progression.Ranks[13];
			}
		}
	}

	private sealed class Layout
	{
		public readonly RectTransform Rect;

		private readonly Vector2 min;

		private readonly Vector2 max;

		private readonly Vector2 pivot;

		private readonly Vector2 size;

		private readonly Vector2 pos;

		private readonly Vector3 scale;

		public Layout(RectTransform r)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Rect = r;
			min = r.anchorMin;
			max = r.anchorMax;
			pivot = r.pivot;
			size = r.sizeDelta;
			pos = r.anchoredPosition;
			scale = ((Transform)r).localScale;
		}

		public void Restore()
		{
			//IL_0015: 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_0037: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Rect))
			{
				Rect.anchorMin = min;
				Rect.anchorMax = max;
				Rect.pivot = pivot;
				Rect.sizeDelta = size;
				Rect.anchoredPosition = pos;
				((Transform)Rect).localScale = scale;
			}
		}
	}

	[HarmonyPatch(typeof(Hud), "UpdateStatusEffects")]
	private static class StatusFlow
	{
		private static void Postfix(Hud __instance, List<RectTransform> ___m_statusEffects)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Current) || (Object)(object)Current.scaledHud != (Object)(object)__instance)
			{
				return;
			}
			foreach (RectTransform ___m_statusEffect in ___m_statusEffects)
			{
				if (Object.op_Implicit((Object)(object)___m_statusEffect))
				{
					Vector2 anchoredPosition = ___m_statusEffect.anchoredPosition;
					___m_statusEffect.anchoredPosition = new Vector2(Mathf.Abs(anchoredPosition.x), anchoredPosition.y);
				}
			}
		}
	}

	[HarmonyPatch(typeof(MessageHud), "UpdateUnlockMsg")]
	private static class UnlockFlow
	{
		private static void Postfix(List<GameObject> ___m_unlockMessages)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			Plugin current = Current;
			if (!Object.op_Implicit((Object)(object)current) || !Object.op_Implicit((Object)(object)current.scaledHud) || !Object.op_Implicit((Object)(object)current.messageRoot))
			{
				return;
			}
			int num = 0;
			foreach (GameObject ___m_unlockMessage in ___m_unlockMessages)
			{
				if (Object.op_Implicit((Object)(object)___m_unlockMessage))
				{
					RectTransform val = (RectTransform)___m_unlockMessage.transform;
					if (!current.unlocks.ContainsKey(val))
					{
						current.unlocks.Add(val, new Layout(val));
					}
					float num2 = Mathf.Max(44f, current.messageLabel.preferredHeight * 0.78f + 18f);
					Pin(val, TopRight, TopRight, current.noticeAnchor + new Vector2(0f, 0f - num2 - (float)(60 * num++)));
					((Transform)val).localScale = Vector3.one * 0.64f;
				}
			}
			if (current.unlocks.Count <= 24)
			{
				return;
			}
			foreach (RectTransform item in new List<RectTransform>(current.unlocks.Keys))
			{
				if (!Object.op_Implicit((Object)(object)item))
				{
					current.unlocks.Remove(item);
				}
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyBlockStaminaUsage")]
	private static class ModifyBlockStaminaUsageBonus
	{
		private static void Postfix(Character ___m_character, ref float staminaUse)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				staminaUse *= 1f - 0.08f * (float)progression.Ranks[4] - ((progression.Role == 1) ? 0.2f : 0f);
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifySneakStaminaUsage")]
	private static class ModifySneakStaminaUsageBonus
	{
		private static void Postfix(Character ___m_character, ref float staminaUse)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				staminaUse *= 1f - 0.1f * (float)progression.Ranks[5];
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyDodgeStaminaUsage")]
	private static class ModifyDodgeStaminaUsageBonus
	{
		private static void Postfix(Character ___m_character, ref float staminaUse)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				staminaUse *= 1f - 0.08f * (float)progression.Ranks[9] - ((progression.Role == 4) ? 0.18f : 0f);
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyRunStaminaDrain")]
	private static class ModifyRunStaminaDrainBonus
	{
		private static void Postfix(Character ___m_character, ref float drain)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				drain *= 1f - 0.08f * (float)progression.Ranks[10] - ((progression.Role == 3) ? 0.1f : 0f);
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyStaminaRegen")]
	private static class ModifyStaminaRegenBonus
	{
		private static void Postfix(Character ___m_character, ref float staminaMultiplier)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				staminaMultiplier *= 1f + 0.06f * (float)progression.Ranks[8];
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyEitrRegen")]
	private static class ModifyEitrRegenBonus
	{
		private static void Postfix(Character ___m_character, ref float eitrMultiplier)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				eitrMultiplier *= 1f + 0.1f * (float)progression.Ranks[7] + ((progression.Role == 2) ? 0.15f : 0f);
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifyMaxCarryWeight")]
	private static class Pack
	{
		private static void Postfix(Character ___m_character, ref float limit)
		{
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				limit += 15 * progression.Ranks[6];
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifySkillLevel")]
	private static class Training
	{
		private static void Postfix(Character ___m_character, SkillType skill, ref float level)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Invalid comparison between Unknown and I4
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Invalid comparison between Unknown and I4
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			Progression progression = For((Player)(object)((___m_character is Player) ? ___m_character : null));
			if (progression != null)
			{
				if ((int)skill == 6)
				{
					level += 5 * progression.Ranks[16];
				}
				if ((int)skill == 2)
				{
					level += 5 * progression.Ranks[17];
				}
				if ((int)skill == 8)
				{
					level += 5 * progression.Ranks[18];
				}
				if ((int)skill == 10)
				{
					level += 5 * progression.Ranks[19];
				}
				if ((int)skill == 9)
				{
					level += 3 * progression.Ranks[11] + ((progression.Role == 2) ? 8 : 0);
				}
				if (progression.Role == 1 && (int)skill == 1)
				{
					level += 8f;
				}
				if (progression.Role == 3 && ((int)skill == 8 || (int)skill == 14))
				{
					level += 10f;
				}
				if (progression.Role == 4 && (int)skill == 2)
				{
					level += 10f;
				}
			}
		}
	}

	internal const string Id = "br.arantel.rpg";

	private const string Request = "br.arantel.rpg.pedido.v3";

	private const string Reply = "br.arantel.rpg.ficha.v3";

	private const string PracticeReply = "br.arantel.rpg.treino.v3";

	private const float PracticeInterval = 2f;

	private const string TrainingStaff = "ArantelTrainingStaff";

	private static readonly string[] BossKeys = new string[7] { "defeated_eikthyr", "defeated_gdking", "defeated_bonemass", "defeated_dragon", "defeated_goblinking", "defeated_queen", "defeated_fader" };

	internal static Plugin Current;

	private readonly Harmony harmony = new Harmony("br.arantel.rpg");

	private ConfigEntry<bool> compact;

	private ConfigEntry<Key> menuKey;

	private ZNet session;

	private long character;

	private Progression state;

	private bool open;

	private bool pending;

	private bool prompted;

	private float nextSync;

	private float nextPractice;

	private float practiceVisibleUntil;

	private string notice = "";

	private static readonly string[] Roles = new string[5] { "", "Guerreiro", "Mago", "Ranger", "Sombra" };

	private static readonly string[] Practices = new string[5] { "", "Espadas, clavas, armas de haste e bloqueio", "Magia elemental e magia de sangue", "Arcos e bestas", "Facas e furtividade" };

	private static readonly string[] Benefits = new string[5] { "", "+20 de vida\n−20% de vigor ao bloquear\n+8 em espadas", "+32 de eitr\n+15% de regeneração de eitr\n+8 em magia elemental", "+20 de vigor\n−10% de vigor ao correr\n+10 em arcos e bestas", "−22% de visibilidade ao espreitar\n−18% de vigor ao esquivar\n+10 em facas" };

	private static readonly string[] Arms = new string[4] { "Sobrevivência", "Ocultação", "Exploração", "Magia" };

	private static readonly string[] Names = new string[20]
	{
		"Raiz vital", "Penumbra", "Fôlego", "Centelha", "Baluarte", "Passo leve", "Alforje", "Fluxo rúnico", "Recobro", "Evasão",
		"Travessia", "Sintonia", "Carvalho", "Véu lunar", "Horizonte", "Estrela-guia", "Guarda", "Lâmina sutil", "Mira firme", "Pacto vital"
	};

	private static readonly string[] Effects = new string[20]
	{
		"+5 de vida máxima", "−8% de visibilidade ao espreitar", "+5 de vigor máximo", "+5 de eitr máximo", "−8% de custo de vigor ao bloquear", "−10% de custo de vigor ao espreitar", "+15 de capacidade de carga", "+10% de regeneração de eitr", "+6% de regeneração de vigor", "−8% de custo de vigor ao esquivar",
		"−8% de custo de vigor ao correr", "+3 em magia elemental", "+12 de vida máxima", "−12% de visibilidade ao espreitar", "+12 de vigor máximo", "+14 de eitr máximo", "+5 em bloqueio", "+5 em facas", "+5 em arcos", "+5 em magia de sangue"
	};

	private static readonly Color Ink = new Color(0.025f, 0.06f, 0.072f, 0.99f);

	private static readonly Color Panel = new Color(0.055f, 0.105f, 0.118f);

	private static readonly Color Gold = new Color(0.93f, 0.78f, 0.52f);

	private static readonly Color Muted = new Color(0.72f, 0.79f, 0.78f);

	private static readonly Color LineColor = new Color(0.26f, 0.33f, 0.33f);

	private static readonly Color[] Colors = (Color[])(object)new Color[4]
	{
		new Color(0.89f, 0.6f, 0.42f),
		new Color(0.59f, 0.74f, 0.96f),
		new Color(0.5f, 0.83f, 0.63f),
		new Color(0.77f, 0.64f, 0.93f)
	};

	private int selectedRole;

	private int selectedNode;

	private Texture2D atlas;

	private Texture2D disc;

	private Texture2D chart;

	private GUIStyle type;

	private static readonly Vector2 Origin = new Vector2(312f, 295f);

	private static readonly int[] Forks = new int[2] { 4, 8 };

	private readonly List<Layout> layouts = new List<Layout>();

	private Hud scaledHud;

	private RectTransform hotbarRoot;

	private RectTransform mapRoot;

	private RectTransform maskRect;

	private RectTransform mapGraphic;

	private RectTransform namesRoot;

	private RectTransform messageRoot;

	private int mapOrder;

	private int namesOrder;

	private CompassMesh meshEffect;

	private Sprite compass;

	private Sprite oldSprite;

	private Image frame;

	private RawImage terrain;

	private bool terrainMaskable;

	private TMP_Text biomeLabel;

	private TextAlignmentOptions biomeAlign;

	private Type frameType;

	private Color frameColor;

	private TextAlignmentOptions messageAlign;

	private TextWrappingModes messageWrap;

	private TMP_Text messageLabel;

	private Image messageIcon;

	private Action releaseNoticeColumn;

	private readonly Dictionary<RectTransform, Layout> unlocks = new Dictionary<RectTransform, Layout>();

	private readonly Vector3[] mapCorners = (Vector3[])(object)new Vector3[4];

	private Vector2 noticeAnchor;

	private static readonly Vector2 TopRight = new Vector2(1f, 1f);

	private static readonly string[] StarterWeapons = new string[5] { "", "Club", "ArantelTrainingStaff", "Bow", "KnifeFlint" };

	private static readonly string[] StarterNames = new string[5] { "", "clava", "bastão rúnico de treino", "arco rudimentar e 20 flechas de madeira", "faca de pederneira" };

	private void Awake()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Invalid comparison between Unknown and I4
		Current = this;
		compact = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "HUDCompacto", false, "Compacta os indicadores de vida, poder e efeitos.");
		menuKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Interface", "Tecla", (Key)68, "Abrir a ficha de Arantel.");
		if ((int)menuKey.Value == 101)
		{
			menuKey.Value = (Key)68;
		}
		PrefabManager.OnVanillaPrefabsAvailable += RegisterTrainingStaff;
		harmony.PatchAll(typeof(Plugin).Assembly);
		InstallNoticeLayout();
		Wildlife.Install(harmony, ((BaseUnityPlugin)this).Logger);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Arantel RPG 1.3.0 carregado.");
	}

	private void OnDestroy()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterTrainingStaff;
		ShowPanel(value: false);
		RestoreHud();
		if (Object.op_Implicit((Object)(object)atlas))
		{
			Object.Destroy((Object)(object)atlas);
		}
		if (Object.op_Implicit((Object)(object)disc))
		{
			Object.Destroy((Object)(object)disc);
		}
		if (Object.op_Implicit((Object)(object)chart))
		{
			Object.Destroy((Object)(object)chart);
		}
		if (Object.op_Implicit((Object)(object)compass))
		{
			Object.Destroy((Object)(object)compass.texture);
			Object.Destroy((Object)(object)compass);
		}
		harmony.UnpatchSelf();
		Current = null;
	}

	private string Handle(string account, long id, int branch, int target)
	{
		try
		{
			int num = 3;
			string[] bossKeys = BossKeys;
			foreach (string text in bossKeys)
			{
				if (ZoneSystem.instance.GetGlobalKey(text))
				{
					num++;
				}
			}
			string path = CharacterStore.PathFor(Path.Combine(Paths.ConfigPath, "ArantelRPG", "fichas"), ZNet.instance.GetWorldUID(), account, id);
			return CharacterStore.Process(path, num, branch, target).Encode();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Erro ao acessar a ficha de Arantel: " + ex));
			return "";
		}
	}

	private void Send(int branch, int target)
	{
		pending = true;
		nextSync = Time.unscaledTime + 3f;
		if (session.IsServer())
		{
			Receive(Handle("local", character, branch, target));
			return;
		}
		ZRpc serverRPC = session.GetServerRPC();
		if (serverRPC != null)
		{
			serverRPC.Invoke("br.arantel.rpg.pedido.v3", new object[2] { branch, target });
		}
	}

	private void Receive(string encoded)
	{
		pending = false;
		if (string.IsNullOrEmpty(encoded))
		{
			notice = "O servidor não conseguiu acessar sua ficha.";
			nextSync = Time.unscaledTime + 10f;
			return;
		}
		Progression progression = Progression.Decode(encoded);
		bool flag = state != null && state.Role == 0 && progression.Role != 0;
		state = progression;
		notice = (flag ? "Classe registrada. Distribua seus pontos abaixo." : "");
		if (progression.Role != 0)
		{
			DeliverStarterKit(Player.m_localPlayer, progression.Role);
		}
		nextSync = Time.unscaledTime + 20f;
	}

	private void ReceivePractice(string encoded)
	{
		if (state == null || string.IsNullOrEmpty(encoded))
		{
			return;
		}
		Progression progression = Progression.Decode(encoded);
		if (progression.Experience > state.Experience)
		{
			practiceVisibleUntil = Time.unscaledTime + 5f;
			if (progression.Level > state.Level && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				((Character)Player.m_localPlayer).Message((MessageType)1, Roles[progression.Role] + " · nível " + progression.Level + "  (+1 ponto de talento)", 0, (Sprite)null, false);
			}
		}
		state = progression;
	}

	private void Update()
	{
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		if (Application.isBatchMode)
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		long num = (((Object)(object)localPlayer == (Object)null) ? 0 : localPlayer.GetPlayerID());
		if ((Object)(object)session != (Object)(object)ZNet.instance || character != num)
		{
			ShowPanel(value: false);
			session = ZNet.instance;
			character = num;
			state = null;
			prompted = (pending = false);
			selectedRole = 0;
			nextSync = (nextPractice = (practiceVisibleUntil = 0f));
			notice = "";
		}
		if (!Object.op_Implicit((Object)(object)session) || num == 0 || !Object.op_Implicit((Object)(object)ZoneSystem.instance) || !Object.op_Implicit((Object)(object)Hud.instance))
		{
			return;
		}
		if (Time.unscaledTime >= nextSync)
		{
			Send(-2, 0);
		}
		if (((Character)localPlayer).IsDead() || ((Character)localPlayer).InIntro() || (Object.op_Implicit((Object)(object)Game.instance) && Game.instance.InIntro(true)) || Menu.IsVisible() || InventoryGui.IsVisible() || (Object.op_Implicit((Object)(object)Chat.instance) && Chat.instance.HasFocus()))
		{
			ShowPanel(value: false);
			return;
		}
		Keyboard current = Keyboard.current;
		if (current != null && (int)menuKey.Value != 0 && ((ButtonControl)current[menuKey.Value]).wasPressedThisFrame)
		{
			ShowPanel(!open);
		}
		else if (!prompted && state != null && state.Role == 0)
		{
			ShowPanel(value: true);
		}
		if (open)
		{
			prompted = true;
		}
	}

	private void ShowPanel(bool value)
	{
		if (open != value)
		{
			open = value;
			GUIManager.BlockInput(value);
		}
	}

	private static Progression For(Player player)
	{
		if (!Object.op_Implicit((Object)(object)Current) || !Object.op_Implicit((Object)(object)player) || !((Object)(object)player == (Object)(object)Player.m_localPlayer) || !((Object)(object)Current.session == (Object)(object)ZNet.instance) || Current.character == 0 || Current.character != player.GetPlayerID())
		{
			return null;
		}
		return Current.state;
	}

	private void LoadArt()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("classes.png"))
		{
			using BinaryReader binaryReader = new BinaryReader(stream);
			atlas = new Texture2D(2, 2);
			ImageConversion.LoadImage(atlas, binaryReader.ReadBytes((int)stream.Length), true);
		}
		using (Stream stream2 = typeof(Plugin).Assembly.GetManifestResourceStream("chart.png"))
		{
			using BinaryReader binaryReader2 = new BinaryReader(stream2);
			chart = new Texture2D(2, 2);
			ImageConversion.LoadImage(chart, binaryReader2.ReadBytes((int)stream2.Length), true);
		}
		disc = RoundTexture(64);
	}

	private static Texture2D RoundTexture(int size)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		Color32[] array = (Color32[])(object)new Color32[size * size];
		float num = (float)size * 0.5f;
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				Vector2 val2 = new Vector2((float)j + 0.5f - num, (float)i + 0.5f - num);
				float magnitude = ((Vector2)(ref val2)).magnitude;
				ref Color32 reference = ref array[i * size + j];
				reference = Color32.op_Implicit(new Color(1f, 1f, 1f, Mathf.Clamp01(num - magnitude)));
			}
		}
		val.SetPixels32(array);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.Apply();
		return val;
	}

	private static void Paint(Rect r, Color color, Texture2D texture = null)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		Color color2 = GUI.color;
		GUI.color = color;
		GUI.DrawTexture(r, (Texture)(object)(Object.op_Implicit((Object)(object)texture) ? texture : Texture2D.whiteTexture));
		GUI.color = color2;
	}

	private void Text(Rect r, string value, int size, Color color, TextAnchor align = (TextAnchor)3, bool bold = false)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		type.fontSize = size;
		type.alignment = align;
		type.normal.textColor = color;
		type.fontStyle = (FontStyle)(bold ? 1 : 0);
		GUI.Label(r, value, type);
	}

	private bool Button(Rect r, string value, bool enabled = true)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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_006a: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		bool flag = enabled && ((Rect)(ref r)).Contains(Event.current.mousePosition);
		Paint(r, flag ? Gold : LineColor);
		Paint(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width - 2f, ((Rect)(ref r)).height - 2f), (Color)(flag ? new Color(0.14f, 0.2f, 0.2f) : Panel));
		Text(r, value, 15, enabled ? Gold : Muted, (TextAnchor)4);
		if (enabled)
		{
			return GUI.Button(r, GUIContent.none, GUIStyle.none);
		}
		return false;
	}

	private void Medal(Rect r, int role)
	{
		//IL_0004: 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)
		int num = role - 1;
		GUI.DrawTextureWithTexCoords(r, (Texture)(object)atlas, new Rect((float)(num % 2) * 0.5f, (float)(1 - num / 2) * 0.5f, 0.5f, 0.5f));
	}

	private void OnGUI()
	{
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_040b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_0496: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || Application.isBatchMode)
		{
			return;
		}
		bool flag = !open && state != null && state.Role != 0 && Time.unscaledTime < practiceVisibleUntil && Object.op_Implicit((Object)(object)Hud.instance) && Hud.instance.IsVisible() && !((Character)Player.m_localPlayer).IsDead() && !Menu.IsVisible() && !InventoryGui.IsVisible();
		if (!open && !flag)
		{
			return;
		}
		if (type == null)
		{
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.wordWrap = true;
			val.padding = new RectOffset(0, 0, 0, 0);
			type = val;
		}
		if (flag)
		{
			float num = Mathf.Clamp((float)Screen.height / 900f, 0.75f, 1.5f);
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.TRS(new Vector3((float)Screen.width * 0.5f - 144f * num, 16f * num, 0f), Quaternion.identity, new Vector3(num, num, 1f));
			try
			{
				Paint(new Rect(0f, 0f, 288f, 39f), Ink);
				DrawExperience(10f, 2f, 268f);
				return;
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}
		if (!Object.op_Implicit((Object)(object)atlas))
		{
			LoadArt();
		}
		bool flag2 = state != null && state.Role != 0;
		int num2 = (flag2 ? 553 : 496);
		int num3 = num2 + 64;
		float num4 = Mathf.Min(new float[3]
		{
			(float)Screen.width / 948f,
			(float)Screen.height / ((float)num3 + 20f),
			1.65f
		});
		Matrix4x4 matrix2 = GUI.matrix;
		GUI.matrix = Matrix4x4.TRS(new Vector3(((float)Screen.width - 928f * num4) / 2f, ((float)Screen.height - (float)num3 * num4) / 2f), Quaternion.identity, new Vector3(num4, num4, 1f));
		try
		{
			Paint(new Rect(0f, 0f, 928f, (float)num3), Ink);
			Paint(new Rect(0f, 0f, 928f, 2f), Gold);
			Text(new Rect(26f, 12f, 500f, 25f), "A R A N T E L", 14, Gold, (TextAnchor)3, bold: true);
			Text(new Rect(25f, 37f, 720f, 48f), (state == null || state.Role == 0) ? "Escolha sua classe" : "Constelação de talentos", 31, Color.white, (TextAnchor)3, bold: true);
			if (Button(new Rect(818f, 25f, 84f, 32f), "Fechar"))
			{
				ShowPanel(value: false);
			}
			if (state == null)
			{
				Text(new Rect(26f, 130f, 550f, 50f), "Consultando a ficha do servidor…", 18, Muted, (TextAnchor)3);
			}
			else if (state.Role == 0)
			{
				DrawClasses();
			}
			else
			{
				DrawTree();
			}
			if (flag2)
			{
				DrawExperience(26f, 499f, 370f);
				Text(new Rect(424f, 492f, 480f, 52f), Practices[state.Role] + "\n+1 ponto de talento por nível de classe", 14, Muted, (TextAnchor)3);
			}
			Paint(new Rect(24f, (float)num2, 880f, 1f), LineColor);
			if (Button(new Rect(26f, (float)(num2 + 15), 204f, 32f), compact.Value ? "HUD compacto  •  ligado" : "Ativar HUD compacto"))
			{
				compact.Value = !compact.Value;
			}
			Text(new Rect(244f, (float)(num2 + 8), 650f, 46f), (notice.Length > 0) ? notice : string.Concat(menuKey.Value, " abre ou fecha a ficha"), 14, Muted, (TextAnchor)3);
		}
		finally
		{
			GUI.matrix = matrix2;
		}
	}

	private void DrawExperience(float x, float y, float width)
	{
		//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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		int level = state.Level;
		bool flag = level == 11;
		int num = Progression.Threshold(level);
		int num2 = state.Experience - num;
		int num3 = Progression.Threshold(level + 1) - num;
		Color color = Colors[state.Role - 1];
		Text(new Rect(x, y, width * 0.6f, 23f), Roles[state.Role] + "  ·  Nível " + level, 15, color, (TextAnchor)3, bold: true);
		Text(new Rect(x + width * 0.6f, y, width * 0.4f, 23f), flag ? "Nível máximo" : (num2 + " / " + num3 + " XP"), 14, Color.white, (TextAnchor)5);
		Paint(new Rect(x, y + 26f, width, 6f), LineColor);
		float num4 = (flag ? 1f : ((float)num2 / (float)num3));
		if (num4 > 0f)
		{
			Paint(new Rect(x, y + 26f, width * num4, 6f), color);
		}
	}

	private void DrawClasses()
	{
		//IL_002c: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: 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)
		Rect val = default(Rect);
		for (int i = 1; i <= 4; i++)
		{
			int num = 26 + (i - 1) * 222;
			((Rect)(ref val))..ctor((float)num, 102f, 208f, 285f);
			Paint(val, (selectedRole == i) ? Gold : LineColor);
			Paint(new Rect((float)(num + 1), 103f, 206f, 283f), Panel);
			Medal(new Rect((float)(num + 49), 117f, 110f, 110f), i);
			Text(new Rect((float)(num + 5), 234f, 198f, 33f), Roles[i], 21, Gold, (TextAnchor)4, bold: true);
			Text(new Rect((float)(num + 9), 273f, 190f, 100f), Benefits[i], 15, Muted, (TextAnchor)1);
			if (GUI.Button(val, GUIContent.none, GUIStyle.none))
			{
				selectedRole = i;
			}
		}
		Text(new Rect(28f, 399f, 560f, 83f), (selectedRole == 0) ? "Sua classe é permanente para este personagem neste mundo." : ("Kit inicial: " + StarterNames[selectedRole] + ".\nGanhe XP com: " + Practices[selectedRole] + ".\nA escolha da classe é permanente neste mundo."), 16, Muted, (TextAnchor)3);
		if (Button(new Rect(617f, 415f, 280f, 46f), (selectedRole == 0) ? "Selecione uma classe" : ("Confirmar " + Roles[selectedRole]), selectedRole > 0 && !pending))
		{
			Send(-1, selectedRole);
		}
	}

	private static Vector2 Point(int node)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		int num = node % 4;
		int num2 = node / 4;
		int num3 = num2 switch
		{
			2 => 153, 
			1 => 131, 
			0 => 65, 
			_ => 250, 
		};
		int num4;
		switch (num2)
		{
		default:
			num4 = 117;
			break;
		case 2:
		case 4:
			num4 = 48;
			break;
		case 1:
			num4 = 115;
			break;
		case 0:
			num4 = 48;
			break;
		}
		int num5 = num4;
		return Origin + new Vector2((float)(((num % 2 != 0) ? 1 : (-1)) * num3), (float)(((num >= 2) ? 1 : (-1)) * num5));
	}

	private static void Edge(Vector2 a, Vector2 b, Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 matrix = GUI.matrix;
		float num = Mathf.Atan2(b.y - a.y, b.x - a.x) * 57.29578f;
		GUI.matrix = matrix * Matrix4x4.TRS(new Vector3(a.x, a.y, 0f), Quaternion.Euler(0f, 0f, num), Vector3.one);
		Vector2 val = b - a;
		Paint(new Rect(0f, -1f, ((Vector2)(ref val)).magnitude, 2f), color);
		GUI.matrix = matrix;
	}

	private void DrawTree()
	{
		//IL_0014: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: 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_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Unknown result type (might be due to invalid IL or missing references)
		//IL_0526: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0648: Unknown result type (might be due to invalid IL or missing references)
		//IL_0651: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		GUI.DrawTexture(new Rect(20f, 99f, 583f, 382f), (Texture)(object)chart);
		Paint(new Rect(616f, 99f, 285f, 382f), Panel);
		for (int i = 0; i < 4; i++)
		{
			Color val = Colors[i];
			Edge(Origin, Point(i), val);
			Edge(Point(12 + i), Point(16 + i), (state.Ranks[12 + i] > 0) ? val : LineColor);
			int[] forks = Forks;
			foreach (int num in forks)
			{
				int num2 = i + num;
				Edge(Point(i), Point(num2), (state.Ranks[i] > 0) ? val : LineColor);
				Edge(Point(num2), Point(12 + i), (state.Ranks[num2] > 0) ? val : LineColor);
			}
			Text(new Rect((float)((i % 2 == 0) ? 37 : 354), (float)((i < 2) ? 104 : 455), 230f, 30f), Arms[i], 16, val, (TextAnchor)((i % 2 == 0) ? 3 : 5), bold: true);
		}
		Medal(new Rect(Origin.x - 27f, Origin.y - 27f, 54f, 54f), state.Role);
		Rect val3 = default(Rect);
		Rect val5 = default(Rect);
		for (int k = 0; k < state.Ranks.Length; k++)
		{
			Vector2 val2 = Point(k);
			float num3 = ((k >= 12) ? 20 : 15);
			((Rect)(ref val3))..ctor(val2.x - num3, val2.y - num3, 2f * num3, 2f * num3);
			Color val4 = Colors[k % 4];
			if (k == selectedNode)
			{
				Paint(new Rect(((Rect)(ref val3)).x - 4f, ((Rect)(ref val3)).y - 4f, ((Rect)(ref val3)).width + 8f, ((Rect)(ref val3)).height + 8f), Gold, disc);
			}
			Paint(val3, state.Unlocked(k) ? val4 : LineColor, disc);
			Paint(new Rect(((Rect)(ref val3)).x + 2f, ((Rect)(ref val3)).y + 2f, ((Rect)(ref val3)).width - 4f, ((Rect)(ref val3)).height - 4f), (state.Ranks[k] > 0) ? Panel : Ink, disc);
			Text(val3, state.Ranks[k].ToString(), 15, state.Unlocked(k) ? Color.white : Muted, (TextAnchor)4, bold: true);
			((Rect)(ref val5))..ctor(val2.x - 49f, ((Rect)(ref val3)).yMax + 1f, 98f, 19f);
			Text(val5, Names[k], 13, state.Unlocked(k) ? Color.white : Muted, (TextAnchor)4);
			if (GUI.Button(val3, GUIContent.none, GUIStyle.none) || GUI.Button(val5, GUIContent.none, GUIStyle.none))
			{
				selectedNode = k;
			}
		}
		int num4 = selectedNode;
		int num5 = state.Ranks[num4];
		int num6 = Progression.Limit(num4);
		Text(new Rect(636f, 112f, 248f, 28f), Roles[state.Role] + "   ·   " + state.Available + " pontos livres", 17, Gold, (TextAnchor)3);
		Paint(new Rect(636f, 154f, 245f, 1f), LineColor);
		Text(new Rect(636f, 170f, 245f, 26f), Arms[num4 % 4] + ((num4 >= 16) ? "   /   Maestria" : ((num4 >= 12) ? "   /   Talento avançado" : "")), 15, Colors[num4 % 4], (TextAnchor)3);
		Text(new Rect(636f, 199f, 245f, 42f), Names[num4], 25, Color.white, (TextAnchor)3, bold: true);
		Text(new Rect(636f, 249f, 245f, 70f), Effects[num4] + ((num6 > 1) ? " por nível." : "."), 18, Color.white, (TextAnchor)3);
		string value = (state.Unlocked(num4) ? ("Nível " + num5 + " de " + num6) : ((num4 >= 16) ? ("Requer " + Names[12 + num4 % 4] + ".") : ((num4 < 12) ? ("Requer " + Names[num4 % 4] + ".") : ("Requer " + Names[4 + num4 % 4] + " ou " + Names[8 + num4 % 4] + "."))));
		Text(new Rect(636f, 327f, 245f, 57f), value, 15, Muted, (TextAnchor)3);
		string value2 = ((num5 >= num6) ? "Talento completo" : ((!state.Unlocked(num4)) ? "Caminho bloqueado" : ((state.Available == 0) ? "Sem pontos livres" : "Investir 1 ponto")));
		if (Button(new Rect(636f, 414f, 245f, 43f), value2, !pending && state.CanBuy(num4)))
		{
			Send(num4, num5 + 1);
		}
	}

	private void Remember(RectTransform r)
	{
		layouts.Add(new Layout(r));
	}

	private static void Pin(RectTransform r, Vector2 anchor, Vector2 pivot, Vector2 pos)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		Vector2 anchorMin = (r.anchorMax = anchor);
		r.anchorMin = anchorMin;
		r.pivot = pivot;
		r.anchoredPosition = pos;
	}

	private void LateUpdate()
	{
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Expected O, but got Unknown
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		Hud instance = Hud.instance;
		if ((Object)(object)scaledHud != (Object)(object)instance || !compact.Value || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
		{
			if (layouts.Count > 0)
			{
				RestoreHud();
			}
			if (!compact.Value || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
		}
		if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Minimap.instance) || !Object.op_Implicit((Object)(object)MessageHud.instance))
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)scaledHud))
		{
			scaledHud = instance;
			HotkeyBar componentInChildren = instance.m_rootObject.GetComponentInChildren<HotkeyBar>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				hotbarRoot = (RectTransform)((Component)componentInChildren).transform;
				Remember(hotbarRoot);
				Pin(hotbarRoot, new Vector2(0.5f, 0f), hotbarRoot.pivot, Vector2.zero);
				RectTransform obj = hotbarRoot;
				((Transform)obj).localScale = ((Transform)obj).localScale * 0.72f;
			}
			RectTransform[] array = (RectTransform[])(object)new RectTransform[2] { instance.m_healthPanel, instance.m_gpRoot };
			foreach (RectTransform val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Remember(val);
					((Transform)val).localScale = ((Transform)val).localScale * 0.84f;
				}
			}
			RectTransform statusEffectListRoot = instance.m_statusEffectListRoot;
			Remember(statusEffectListRoot);
			Pin(statusEffectListRoot, new Vector2(0f, 1f), TopRight, new Vector2(60f, -12f));
			((Transform)statusEffectListRoot).localScale = ((Transform)statusEffectListRoot).localScale * 0.57f;
			RoundMap(Minimap.instance);
			PlaceMessages(MessageHud.instance);
		}
		if (Object.op_Implicit((Object)(object)hotbarRoot) && ((Component)hotbarRoot).gameObject.activeInHierarchy)
		{
			PlaceHotbar();
		}
		if (Object.op_Implicit((Object)(object)mapRoot) && Object.op_Implicit((Object)(object)messageRoot))
		{
			mapRoot.GetWorldCorners(mapCorners);
			RectTransform val2 = (RectTransform)((Transform)messageRoot).parent;
			Vector2 val3 = Vector2.op_Implicit(((Transform)val2).InverseTransformPoint(mapCorners[3]));
			Rect rect = val2.rect;
			noticeAnchor = val3 - ((Rect)(ref rect)).max + new Vector2(0f, -35f);
			messageRoot.anchoredPosition = noticeAnchor;
			bool flag = Object.op_Implicit((Object)(object)messageIcon.sprite) && ((Behaviour)messageIcon).isActiveAndEnabled && ((Graphic)messageIcon).canvasRenderer.GetAlpha() > 0.01f;
			messageLabel.rectTransform.anchoredPosition = new Vector2((float)(flag ? (-37) : (-9)), -6f);
		}
	}

	private void PlaceHotbar()
	{
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		float num = float.PositiveInfinity;
		float num2 = float.NegativeInfinity;
		float num3 = float.PositiveInfinity;
		for (int i = 0; i < ((Transform)hotbarRoot).childCount; i++)
		{
			Transform child = ((Transform)hotbarRoot).GetChild(i);
			RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
			if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf)
			{
				Rect rect = val.rect;
				Vector3 localPosition = ((Transform)val).localPosition;
				Vector3 localScale = ((Transform)val).localScale;
				num = Mathf.Min(num, localPosition.x + ((Rect)(ref rect)).xMin * localScale.x);
				num2 = Mathf.Max(num2, localPosition.x + ((Rect)(ref rect)).xMax * localScale.x);
				num3 = Mathf.Min(num3, localPosition.y + ((Rect)(ref rect)).yMin * localScale.y);
			}
		}
		if (!(num > num2))
		{
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((0f - (num + num2)) * 0.5f * ((Transform)hotbarRoot).localScale.x, 20f - num3 * ((Transform)hotbarRoot).localScale.y);
			if (hotbarRoot.anchoredPosition != val2)
			{
				hotbarRoot.anchoredPosition = val2;
			}
		}
	}

	private void RoundMap(Minimap map)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Expected O, but got Unknown
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Expected O, but got Unknown
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		mapRoot = (RectTransform)map.m_smallRoot.transform;
		if (!Object.op_Implicit((Object)(object)compass))
		{
			Texture2D val = RoundTexture(192);
			compass = Sprite.Create(val, new Rect(0f, 0f, 192f, 192f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
		}
		frame = ((Component)mapRoot).GetComponent<Image>();
		if (Object.op_Implicit((Object)(object)frame))
		{
			oldSprite = frame.overrideSprite;
			frameType = frame.type;
			frameColor = ((Graphic)frame).color;
			frame.overrideSprite = compass;
			frame.type = (Type)0;
			((Graphic)frame).color = new Color(0.58f, 0.48f, 0.3f, 0.96f);
		}
		terrain = map.m_mapImageSmall;
		terrainMaskable = ((MaskableGraphic)terrain).maskable;
		((MaskableGraphic)terrain).maskable = false;
		((Graphic)terrain).SetMaterialDirty();
		mapGraphic = ((Graphic)terrain).rectTransform;
		Transform obj = ((Transform)mapGraphic).Find("wind_marker");
		RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
		if (Object.op_Implicit((Object)(object)val2))
		{
			Remember(val2);
			val2.anchoredPosition = new Vector2(-51f, -51f);
		}
		biomeLabel = map.m_biomeNameSmall;
		if (Object.op_Implicit((Object)(object)biomeLabel))
		{
			RectTransform rectTransform = biomeLabel.rectTransform;
			Remember(rectTransform);
			biomeAlign = biomeLabel.alignment;
			Pin(rectTransform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -12f));
			biomeLabel.alignment = (TextAlignmentOptions)514;
		}
		namesRoot = map.m_pinNameRootSmall;
		mapOrder = ((Transform)mapGraphic).GetSiblingIndex();
		namesOrder = ((Transform)namesRoot).GetSiblingIndex();
		GameObject val3 = new GameObject("Arantel • bússola", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Mask)
		});
		maskRect = (RectTransform)val3.transform;
		((Transform)maskRect).SetParent((Transform)(object)mapRoot, false);
		((Transform)maskRect).SetSiblingIndex(mapOrder);
		maskRect.anchorMin = Vector2.zero;
		maskRect.anchorMax = Vector2.one;
		maskRect.offsetMin = Vector2.zero;
		maskRect.offsetMax = Vector2.zero;
		Image component = val3.GetComponent<Image>();
		component.sprite = compass;
		((Graphic)component).raycastTarget = false;
		val3.GetComponent<Mask>().showMaskGraphic = false;
		((Transform)mapGraphic).SetParent((Transform)(object)maskRect, false);
		((Transform)namesRoot).SetParent((Transform)(object)maskRect, false);
		meshEffect = ((Component)mapGraphic).gameObject.AddComponent<CompassMesh>();
	}

	private void PlaceMessages(MessageHud hud)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ba: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: 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)
		if (releaseNoticeColumn != null)
		{
			releaseNoticeColumn();
		}
		messageLabel = hud.m_messageText;
		messageIcon = hud.m_messageIcon;
		RectTransform rectTransform = messageLabel.rectTransform;
		RectTransform rectTransform2 = ((Graphic)messageIcon).rectTransform;
		messageRoot = (RectTransform)((Transform)rectTransform).parent;
		Remember(messageRoot);
		Remember(rectTransform);
		Remember(rectTransform2);
		messageAlign = messageLabel.alignment;
		messageWrap = messageLabel.textWrappingMode;
		Pin(messageRoot, TopRight, TopRight, Vector2.zero);
		messageRoot.sizeDelta = new Vector2(294f, 100f);
		RectTransform obj = messageRoot;
		((Transform)obj).localScale = ((Transform)obj).localScale * 0.78f;
		Pin(rectTransform, TopRight, TopRight, new Vector2(-9f, -6f));
		rectTransform.sizeDelta = new Vector2(252f, 100f);
		messageLabel.alignment = (TextAlignmentOptions)260;
		messageLabel.textWrappingMode = (TextWrappingModes)1;
		Pin(rectTransform2, TopRight, TopRight, new Vector2(-4f, -4f));
		rectTransform2.sizeDelta = new Vector2(27f, 27f);
	}

	private void InstallNoticeLayout()
	{
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Expected O, but got Unknown
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Expected O, but got Unknown
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		if (!Chainloader.PluginInfos.ContainsKey("com.meadworks.crucible.ui"))
		{
			return;
		}
		Type type = AccessTools.TypeByName("ExtraPotions.Meadworks.Crucible.UI.KitNativeMenus");
		Type type2 = AccessTools.TypeByName("ExtraPotions.Meadworks.Crucible.UI.KitNativeNotices+NoticeWrapping");
		if (!(type == null) && !(type2 == null))
		{
			MethodInfo methodInfo = AccessTools.Method(type, "RestoreColumn", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(type, "PlaceRow", (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.Method(type, "NoticePlate", (Type[])null, (Type[])null);
			MethodInfo methodInfo4 = AccessTools.Method(type2, "Refresh", (Type[])null, (Type[])null);
			if (!(methodInfo == null) && !(methodInfo2 == null) && !(methodInfo3 == null) && !(methodInfo4 == null) && !(AccessTools.Field(type2, "text") == null))
			{
				releaseNoticeColumn = (Action)Delegate.CreateDelegate(typeof(Action), methodInfo);
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Plugin), "PlaceNativeRow", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(Plugin), "WrapNativeNotice", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "CompactPlate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
	}

	private static bool PlaceNativeRow(MessageHud hud)
	{
		if (Object.op_Implicit((Object)(object)Current) && Object.op_Implicit((Object)(object)Current.messageLabel))
		{
			return (Object)(object)Current.messageLabel != (Object)(object)hud.m_messageText;
		}
		return true;
	}

	private static bool WrapNativeNotice(TMP_Text ___text)
	{
		if (Object.op_Implicit((Object)(object)Current) && Object.op_Implicit((Object)(object)Current.messageLabel))
		{
			return (Object)(object)Current.messageLabel != (Object)(object)___text;
		}
		return true;
	}

	private static void CompactPlate(TMP_Text text, ref float left, ref RectTransform icon, ref bool __result)
	{
		//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_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_0051: Unknown result type (might be due to invalid IL or missing references)
		Plugin current = Current;
		if (Object.op_Implicit((Object)(object)current) && Object.op_Implicit((Object)(object)current.messageLabel) && !((Object)(object)text != (Object)(object)current.messageLabel))
		{
			RectTransform rectTransform = text.rectTransform;
			Bounds textBounds = text.textBounds;
			left = ((Transform)rectTransform).TransformPoint(((Bounds)(ref textBounds)).min).x - 12f * Mathf.Abs(((Transform)rectTransform).lossyScale.x);
			icon = ((Graphic)current.messageIcon).rectTransform;
			__result = true;
		}
	}

	private void RestoreHud()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)scaledHud) && Object.op_Implicit((Object)(object)scaledHud.m_statusEffectListRoot))
		{
			foreach (RectTransform item in (Transform)scaledHud.m_statusEffectListRoot)
			{
				RectTransform val = item;
				if ((Object)(object)val != (Object)(object)scaledHud.m_statusEffectTemplate)
				{
					Vector2 anchoredPosition = val.anchoredPosition;
					val.anchoredPosition = new Vector2(0f - Mathf.Abs(anchoredPosition.x), anchoredPosition.y);
				}
			}
		}
		foreach (Layout value in unlocks.Values)
		{
			value.Restore();
		}
		unlocks.Clear();
		if (Object.op_Implicit((Object)(object)messageLabel))
		{
			messageLabel.alignment = messageAlign;
			messageLabel.textWrappingMode = messageWrap;
		}
		foreach (Layout layout in layouts)
		{
			layout.Restore();
		}
		layouts.Clear();
		if (Object.op_Implicit((Object)(object)meshEffect))
		{
			((Behaviour)meshEffect).enabled = false;
			Object.Destroy((Object)(object)meshEffect);
		}
		if (Object.op_Implicit((Object)(object)maskRect))
		{
			if (Object.op_Implicit((Object)(object)mapRoot) && Object.op_Implicit((Object)(object)mapGraphic))
			{
				((Transform)mapGraphic).SetParent((Transform)(object)mapRoot, false);
				((Transform)mapGraphic).SetSiblingIndex(mapOrder);
			}
			if (Object.op_Implicit((Object)(object)mapRoot) && Object.op_Implicit((Object)(object)namesRoot))
			{
				((Transform)namesRoot).SetParent((Transform)(object)mapRoot, false);
				((Transform)namesRoot).SetSiblingIndex(namesOrder);
			}
			((Component)maskRect).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)maskRect).gameObject);
		}
		if (Object.op_Implicit((Object)(object)terrain))
		{
			((MaskableGraphic)terrain).maskable = terrainMaskable;
			((Graphic)terrain).SetMaterialDirty();
			terrain = null;
		}
		if (Object.op_Implicit((Object)(object)biomeLabel))
		{
			biomeLabel.alignment = biomeAlign;
			biomeLabel = null;
		}
		if (Object.op_Implicit((Object)(object)frame))
		{
			frame.overrideSprite = oldSprite;
			frame.type = frameType;
			((Graphic)frame).color = frameColor;
		}
		hotbarRoot = null;
		messageLabel = null;
		messageIcon = null;
		messageRoot = null;
		mapRoot = null;
		frame = null;
		scaledHud = null;
	}

	private void RegisterTrainingStaff()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		CustomItem val = new CustomItem("ArantelTrainingStaff", "Club");
		SharedData shared = val.ItemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared;
		shared.m_name = "Bastão rúnico de treino";
		shared.m_description = "Um bastão de madeira entalhado com runas. Golpes corpo a corpo treinam magia elemental.";
		shared.m_skillType = (SkillType)9;
		shared.m_damages.m_blunt = 4f;
		shared.m_damages.m_fire = 2f;
		shared.m_maxQuality = 1;
		if (ItemManager.Instance.AddItem(val))
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterTrainingStaff;
		}
	}

	private void DeliverStarterKit(Player player, int role)
	{
		if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead() || ((Character)player).InIntro() || !Object.op_Implicit((Object)(object)ObjectDB.instance))
		{
			return;
		}
		string key = "br.arantel.rpg.kit." + session.GetWorldUID().ToString("X16");
		int result = 0;
		if (player.m_customData.TryGetValue(key, out var value) && !int.TryParse(value, out result))
		{
			return;
		}
		int num = ((role != 3) ? 1 : 21);
		Inventory inventory = ((Humanoid)player).GetInventory();
		while (result < num)
		{
			string text = ((result == 0) ? StarterWeapons[role] : "ArrowWood");
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
			if (!Object.op_Implicit((Object)(object)itemPrefab) || !inventory.CanAddItem(itemPrefab, 1) || inventory.AddItem(text, 1, 1, 0, 0L, "", false, false) == null)
			{
				notice = "Kit inicial pendente. A entrega será tentada novamente quando houver espaço.";
				return;
			}
			Dictionary<string, string> customData = player.m_customData;
			int num2 = ++result;
			customData[key] = num2.ToString();
		}
		if (value != num.ToString())
		{
			((Character)player).Message((MessageType)1, "Kit de " + Roles[role] + " recebido.", 0, (Sprite)null, false);
		}
	}
}
internal sealed class Progression
{
	public const int MaxRank = 3;

	public const int InitialPoints = 3;

	public const int MaxBudget = 10;

	public const int MaxLevel = 11;

	public const int PracticeBranch = 1000;

	public int Role;

	public int Experience;

	public int Budget = 3;

	public readonly int[] Ranks = new int[20];

	public int Available => Budget + Level - 1 - Ranks.Sum();

	public int Level
	{
		get
		{
			int i;
			for (i = 1; i < 11 && Experience >= Threshold(i + 1); i++)
			{
			}
			return i;
		}
	}

	public static int Threshold(int level)
	{
		return 5 * (level - 1) * (level + 2);
	}

	public static bool TrainsClass(int role, SkillType skill)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Invalid comparison between Unknown and I4
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Invalid comparison between Unknown and I4
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Invalid comparison between Unknown and I4
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Invalid comparison between Unknown and I4
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Invalid comparison between Unknown and I4
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Invalid comparison between Unknown and I4
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Invalid comparison between Unknown and I4
		switch (role)
		{
		case 1:
			if ((int)skill != 1 && (int)skill != 6 && (int)skill != 3)
			{
				return (int)skill == 4;
			}
			return true;
		case 2:
			if ((int)skill != 9)
			{
				return (int)skill == 10;
			}
			return true;
		case 3:
			if ((int)skill != 8)
			{
				return (int)skill == 14;
			}
			return true;
		case 4:
			if ((int)skill != 2)
			{
				return (int)skill == 101;
			}
			return true;
		default:
			return false;
		}
	}

	public void Apply(int branch, int target)
	{
		if (branch >= 1000 && target == Experience && TrainsClass(Role, (SkillType)(branch - 1000)))
		{
			Experience = Math.Min(Threshold(11), Experience + 2);
		}
		if (branch == -1 && Role == 0 && target >= 1 && target <= 4)
		{
			Role = target;
		}
		if (branch >= 0 && branch < Ranks.Length && CanBuy(branch) && target == Ranks[branch] + 1 && target <= 3)
		{
			Ranks[branch] = target;
		}
	}

	public static int Limit(int node)
	{
		if (node < 12)
		{
			return 3;
		}
		return 1;
	}

	public bool Unlocked(int node)
	{
		if (node < 4)
		{
			return true;
		}
		int num = node % 4;
		if (node >= 16)
		{
			return Ranks[12 + num] > 0;
		}
		if (node >= 12)
		{
			if (Ranks[4 + num] <= 0)
			{
				return Ranks[8 + num] > 0;
			}
			return true;
		}
		return Ranks[num] > 0;
	}

	public bool CanBuy(int node)
	{
		if (Role != 0 && Available > 0 && Ranks[node] < Limit(node))
		{
			return Unlocked(node);
		}
		return false;
	}

	public string Encode()
	{
		return string.Join(",", new int[2] { Role, Budget }.Concat(Ranks).Concat(new int[1] { Experience }));
	}

	public static Progression Decode(string encoded)
	{
		string[] array = encoded.Split(',');
		if (array.Length != 6 && array.Length != 18 && array.Length != 19 && array.Length != 23)
		{
			throw new InvalidDataException("Ficha incompleta.");
		}
		int[] array2 = Array.ConvertAll(array, (string s) => int.Parse(s, NumberStyles.None, CultureInfo.InvariantCulture));
		Progression progression = new Progression();
		progression.Role = array2[0];
		progression.Budget = array2[1];
		Progression progression2 = progression;
		if (progression2.Role < 0 || progression2.Role > 4 || progression2.Budget < 3 || progression2.Budget > 10)
		{
			throw new InvalidDataException("Classe ou orçamento inválido.");
		}
		bool flag = array2.Length == 19 || array2.Length == 23;
		if (flag)
		{
			progression2.Experience = array2[^1];
		}
		if (progression2.Experience < 0 || progression2.Experience > Threshold(11) || (progression2.Role == 0 && progression2.Experience != 0))
		{
			throw new InvalidDataException("Experiência de classe inválida.");
		}
		Array.Copy(array2, 2, progression2.Ranks, 0, array2.Length - (flag ? 3 : 2));
		for (int num = 0; num < progression2.Ranks.Length; num++)
		{
			if (progression2.Ranks[num] > Limit(num) || (progression2.Ranks[num] > 0 && !progression2.Unlocked(num)))
			{
				throw new InvalidDataException("Caminho de talento inválido.");
			}
		}
		if (Array.Exists(progression2.Ranks, (int rank) => rank < 0 || rank > 3) || progression2.Available < 0 || (progression2.Role == 0 && progression2.Available != progression2.Budget))
		{
			throw new InvalidDataException("Distribuição de pontos inválida.");
		}
		return progression2;
	}
}
internal static class CharacterStore
{
	public static string PathFor(string root, long world, string account, long character)
	{
		using SHA256 sHA = SHA256.Create();
		string text = BitConverter.ToString(sHA.ComputeHash(Encoding.UTF8.GetBytes(account))).Replace("-", "");
		return Path.Combine(root, world.ToString("X16"), text + "-" + character.ToString("X16") + ".txt");
	}

	public static Progression Process(string path, int earned, int branch, int target)
	{
		string text;
		try
		{
			text = File.ReadAllText(path);
		}
		catch (FileNotFoundException)
		{
			text = null;
		}
		catch (DirectoryNotFoundException)
		{
			text = null;
		}
		Progression progression = ((text == null) ? new Progression() : Progression.Decode(text));
		progression.Budget = Math.Max(progression.Budget, earned);
		progression.Apply(branch, target);
		string text2 = progression.Encode();
		if (text != text2 && (text != null || progression.Role != 0))
		{
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			string text3 = path + "." + Guid.NewGuid().ToString("N") + ".tmp";
			try
			{
				File.WriteAllText(text3, text2);
				if (text == null)
				{
					File.Move(text3, path);
				}
				else
				{
					File.Replace(text3, path, null);
				}
			}
			finally
			{
				if (File.Exists(text3))
				{
					File.Delete(text3);
				}
			}
		}
		return progression;
	}
}
[HarmonyPatch(typeof(FejdStartup), "Update")]
internal static class SplashReady
{
	private static bool done;

	[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
	private static extern IntPtr OpenEvent(uint access, bool inherit, string name);

	[DllImport("kernel32.dll")]
	private static extern bool SetEvent(IntPtr handle);

	[DllImport("kernel32.dll")]
	private static extern bool CloseHandle(IntPtr handle);

	private static void Postfix()
	{
		if (done)
		{
			return;
		}
		done = true;
		if (Environment.OSVersion.Platform != PlatformID.Win32NT)
		{
			return;
		}
		using Process process = Process.GetCurrentProcess();
		IntPtr intPtr = OpenEvent(2u, inherit: false, "Local\\ArantelReady-" + process.Id);
		if (intPtr == IntPtr.Zero)
		{
			return;
		}
		try
		{
			SetEvent(intPtr);
		}
		finally
		{
			CloseHandle(intPtr);
		}
	}
}
public sealed class CompassMesh : BaseMeshEffect
{
	public override void ModifyMesh(VertexHelper mesh)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		if (((UIBehaviour)this).IsActive() && mesh.currentVertCount == 4)
		{
			UIVertex val = default(UIVertex);
			UIVertex val2 = default(UIVertex);
			mesh.PopulateUIVertex(ref val, 0);
			mesh.PopulateUIVertex(ref val2, 2);
			mesh.Clear();
			for (int i = -1; i < 64; i++)
			{
				float num = (float)i * (float)Math.PI / 32f;
				float num2 = ((i < 0) ? 0.5f : (0.5f + 0.5f * Mathf.Cos(num)));
				float num3 = ((i < 0) ? 0.5f : (0.5f + 0.5f * Mathf.Sin(num)));
				UIVertex val3 = val;
				val3.position = new Vector3(Mathf.Lerp(val.position.x, val2.position.x, num2), Mathf.Lerp(val.position.y, val2.position.y, num3), val.position.z);
				val3.uv0 = new Vector4(Mathf.Lerp(val.uv0.x, val2.uv0.x, num2), Mathf.Lerp(val.uv0.y, val2.uv0.y, num3), val.uv0.z, val.uv0.w);
				mesh.AddVert(val3);
			}
			for (int j = 0; j < 64; j++)
			{
				mesh.AddTriangle(0, 1 + (j + 1) % 64, 1 + j);
			}
		}
	}
}
internal static class Wildlife
{
	[ThreadStatic]
	private static Biome victimBiome;

	[ThreadStatic]
	private static Biome contractBiome;

	private static readonly Biome[] Tiers = (Biome[])(object)new Biome[7]
	{
		(Biome)1,
		(Biome)8,
		(Biome)2,
		(Biome)4,
		(Biome)16,
		(Biome)512,
		(Biome)32
	};

	internal static void Install(Harmony harmony, ManualLogSource log)
	{
		Type type = AccessTools.TypeByName("BountyBoard.Plugin");
		if (!(type == null))
		{
			Type type2 = AccessTools.TypeByName("BountyBoard.Rules");
			MethodInfo methodInfo = AccessTools.Method(type, "ReportKill", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(type, "ToServer", (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.Method(type, "ServerKill", (Type[])null, (Type[])null);
			MethodInfo methodInfo4 = AccessTools.Method(type2, "InTier", (Type[])null, (Type[])null);
			if (methodInfo == null || methodInfo2 == null || methodInfo3 == null || methodInfo4 == null)
			{
				log.LogWarning((object)"Versão do mural incompatível com a extensão de fauna.");
				return;
			}
			harmony.Patch((MethodBase)methodInfo, Hook("BeginReport"), (HarmonyMethod)null, (HarmonyMethod)null, Hook("EndReport"), (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo2, Hook("AddBiome"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo3, Hook("BeginKill"), (HarmonyMethod)null, (HarmonyMethod)null, Hook("EndKill"), (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, Hook("MatchBiome"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			log.LogInfo((object)"Fauna de Arantel integrada aos contratos de bioma do Bounty Board.");
		}
	}

	private static HarmonyMethod Hook(string name)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		return new HarmonyMethod(typeof(Wildlife), name, (Type[])null);
	}

	private static void BeginReport(Character victim, out Biome __state)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected I4, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		__state = (Biome)(int)victimBiome;
		victimBiome = (Biome)(Object.op_Implicit((Object)(object)victim) ? ((int)Heightmap.FindBiome(((Component)victim).transform.position)) : 0);
	}

	private static void EndReport(Biome __state)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		victimBiome = __state;
	}

	private static void AddBiome(string rpc, ref string payload)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected I4, but got Unknown
		if (rpc == "DH_BB_Kill" && (int)victimBiome != 0)
		{
			payload = payload + "|" + (int)victimBiome;
		}
	}

	private static void BeginKill(string payload, out Biome __state)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected I4, but got Unknown
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		__state = (Biome)(int)contractBiome;
		contractBiome = (Biome)0;
		if (!string.IsNullOrEmpty(payload))
		{
			string[] array = payload.Split('|');
			if (array.Length == 4 && int.TryParse(array[3], out var result))
			{
				contractBiome = (Biome)result;
			}
		}
	}

	private static void EndKill(Biome __state)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		contractBiome = __state;
	}

	private static void MatchBiome(int tier, string prefab, ref bool __result)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		if (!__result && tier >= 0 && tier < Tiers.Length && (int)contractBiome == (int)Tiers[tier] && Object.op_Implicit((Object)(object)ZNetScene.instance))
		{
			GameObject prefab2 = ZNetScene.instance.GetPrefab(prefab);
			__result = Object.op_Implicit((Object)(object)prefab2) && Object.op_Implicit((Object)(object)prefab2.GetComponent<Character>()) && !Object.op_Implicit((Object)(object)prefab2.GetComponent<Player>());
		}
	}
}