Decompiled source of Wayfarers of Aurai v1.0.0

WayfarersOfAurai.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Photon;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("WayfarersOfAurai")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WayfarersOfAurai")]
[assembly: AssemblyTitle("WayfarersOfAurai")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TeleportTrainer;

internal static class CastSound
{
	private const int MistSkillID = 8200170;

	public static void Play(Transform at)
	{
		bool flag = false;
		Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(8200170);
		if (Object.op_Implicit((Object)(object)itemPrefab))
		{
			PlaySoundEffect[] componentsInChildren = ((Component)itemPrefab).GetComponentsInChildren<PlaySoundEffect>(true);
			foreach (PlaySoundEffect val in componentsInChildren)
			{
				if (val.Sounds != null)
				{
					Sounds[] sounds = val.Sounds;
					for (int j = 0; j < sounds.Length; j++)
					{
						PlayOne(sounds[j], at);
						flag = true;
					}
				}
			}
		}
		if (!flag)
		{
			Plugin.Log.LogInfo((object)"No sound found on the Mist skill; using the general boon sound.");
			PlayOne((Sounds)12903, at);
		}
	}

	private static void PlayOne(Sounds sound, Transform at)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Global.AudioManager.PlaySoundAtPosition(sound, at, 0f, 1f, 1f, 1f, 1f);
	}
}
internal static class Fatigue
{
	public const string Identifier = "WayfarersFatigue";

	private static readonly List<string> pending = new List<string>();

	private static readonly Dictionary<string, float> applied = new Dictionary<string, float>();

	private static double lastGameTime = -1.0;

	private const double RestHours = 0.9;

	public static void ResetClock()
	{
		lastGameTime = -1.0;
	}

	private static void CheckForRest()
	{
		if (!Object.op_Implicit((Object)(object)CharacterManager.Instance) || !Object.op_Implicit((Object)(object)NetworkLevelLoader.Instance) || NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			return;
		}
		List<Character> list = (from c in Rules.Players()
			where c.IsLocalPlayer && Object.op_Implicit((Object)(object)c.StatusEffectMngr)
			select c).ToList();
		if (list.Count == 0)
		{
			return;
		}
		double gameTime = EnvironmentConditions.GameTime;
		bool num = lastGameTime >= 0.0 && gameTime - lastGameTime >= 0.9;
		lastGameTime = gameTime;
		if (!num)
		{
			return;
		}
		foreach (Character item in list.Where((Character c) => c.StatusEffectMngr.HasStatusEffect("WayfarersFatigue")))
		{
			item.StatusEffectMngr.RemoveStatusWithIdentifierName("WayfarersFatigue");
			Plugin.Log.LogInfo((object)"Fatigue cleared by resting.");
		}
	}

	public static void Watch()
	{
		CheckForRest();
		foreach (KeyValuePair<string, float> item in applied.ToList())
		{
			Character val = (Object.op_Implicit((Object)(object)CharacterManager.Instance) ? CharacterManager.Instance.GetCharacter(item.Key) : null);
			if (Object.op_Implicit((Object)(object)val) && !NetworkLevelLoader.Instance.IsGameplayPaused && !val.StatusEffectMngr.HasStatusEffect("WayfarersFatigue"))
			{
				Plugin.Log.LogInfo((object)$"Fatigue ended after about {Time.time - item.Value:0} seconds.");
				applied.Remove(item.Key);
			}
		}
	}

	public static void Register()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//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_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		SL_StatusEffect val = new SL_StatusEffect();
		val.TargetStatusIdentifier = "Doom";
		val.NewStatusID = -27520;
		val.StatusIdentifier = "WayfarersFatigue";
		val.Name = "Wayfarer's Fatigue";
		val.Description = "30% slower stamina recovery and -15 maximum stamina. You cannot teleport. Sleeping clears it.";
		val.Lifespan = Plugin.FatigueSeconds.Value;
		val.IsMalusEffect = true;
		val.Purgeable = false;
		val.DisplayedInHUD = true;
		val.IsHidden = false;
		val.PlayFXOnActivation = false;
		val.EffectBehaviour = (EditBehaviours)2;
		SL_EffectTransform[] array = new SL_EffectTransform[1];
		SL_EffectTransform val2 = new SL_EffectTransform();
		val2.TransformName = "Effects";
		val2.Effects = (SL_Effect[])(object)new SL_Effect[2]
		{
			(SL_Effect)new SL_AffectStat
			{
				Stat_Tag = "StaminaRegen",
				AffectQuantity = -30f,
				IsModifier = true
			},
			(SL_Effect)new SL_AffectStat
			{
				Stat_Tag = "MaxStamina",
				AffectQuantity = -15f,
				IsModifier = false
			}
		};
		array[0] = val2;
		val.Effects = (SL_EffectTransform[])(object)array;
		val.OnTemplateApplied += delegate(StatusEffect prefab)
		{
			prefab.OverrideIcon = Icons.Load("fatigue");
		};
		((ContentTemplate)val).ApplyTemplate();
	}

	public static void Queue(IEnumerable<Character> characters)
	{
		pending.AddRange(characters.Select((Character c) => ((object)c.UID/*cast due to .constrained prefix*/).ToString()));
	}

	public static void ApplyPending()
	{
		foreach (string uid in pending.Distinct().ToList())
		{
			Character character = CharacterManager.Instance.GetCharacter(uid);
			if (Object.op_Implicit((Object)(object)character))
			{
				Apply(character);
				pending.RemoveAll((string p) => p == uid);
			}
		}
	}

	private static void Apply(Character character)
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		StatusEffect statusEffectPrefab = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("WayfarersFatigue");
		if (!Object.op_Implicit((Object)(object)statusEffectPrefab))
		{
			Plugin.Log.LogError((object)"Wayfarer's Fatigue was not created.");
			return;
		}
		float num = Plugin.FatigueSeconds.Value;
		Town town = Towns.All.First((Town t) => t.Perk == Perk.ShorterFatigue);
		if (((CharacterKnowledge)character.Inventory.SkillKnowledge).IsItemLearned(town.PassiveID))
		{
			num *= town.PerkValue;
		}
		StatusData statusData = statusEffectPrefab.StatusData;
		statusEffectPrefab.StatusData = new StatusData(statusData)
		{
			LifeSpan = num
		};
		character.StatusEffectMngr.AddStatusEffect(statusEffectPrefab, (Character)null);
		statusEffectPrefab.StatusData = statusData;
		applied[((object)character.UID/*cast due to .constrained prefix*/).ToString()] = Time.time;
		Plugin.Log.LogInfo((object)$"Fatigue applied for {num:0} seconds.");
	}
}
internal static class Icons
{
	public static Sprite Load(string name)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_008b: 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)
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name + ".png");
		if (stream == null)
		{
			Plugin.Log.LogError((object)("Missing icon " + name + ".png"));
			return null;
		}
		MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		ImageConversion.LoadImage(val, memoryStream.ToArray());
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Object.DontDestroyOnLoad((Object)(object)val);
		Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
		Object.DontDestroyOnLoad((Object)(object)obj);
		return obj;
	}
}
public class Network : MonoBehaviour
{
	private const int ViewID = 913;

	public static Network Instance;

	internal static void Create()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("TeleportTrainer_RPC");
		Object.DontDestroyOnLoad((Object)val);
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		val.AddComponent<Network>();
	}

	internal void Awake()
	{
		Instance = this;
		((Component)this).gameObject.AddComponent<PhotonView>().viewID = 913;
	}

	internal void ShowCircle(Character caster, Town town, float radius)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)this).photonView.RPC("RPC_ShowCircle", (PhotonTargets)1, new object[4]
		{
			((object)caster.UID/*cast due to .constrained prefix*/).ToString(),
			town.TeleportID,
			((Component)caster).transform.position,
			radius
		});
	}

	internal void HideCircle(string casterUID)
	{
		((MonoBehaviour)this).photonView.RPC("RPC_HideCircle", (PhotonTargets)1, new object[1] { casterUID });
	}

	internal void Travel(Town town)
	{
		((MonoBehaviour)this).photonView.RPC("RPC_Travel", (PhotonTargets)0, new object[1] { town.TeleportID });
	}

	[PunRPC]
	private void RPC_ShowCircle(string casterUID, int teleportID, Vector3 centre, float radius)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Character character = CharacterManager.Instance.GetCharacter(casterUID);
		Town town = Find(teleportID);
		if (Object.op_Implicit((Object)(object)character) && town != null)
		{
			TeleportCircle.Begin(character, town, centre, radius, isCaster: false);
		}
	}

	[PunRPC]
	private void RPC_HideCircle(string casterUID)
	{
		TeleportCircle.Remove(casterUID);
	}

	[PunRPC]
	private void RPC_Travel(int teleportID)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Town town = Find(teleportID);
		if (town != null)
		{
			Fatigue.Queue(from p in Rules.Players()
				where p.IsLocalPlayer
				select p);
			if (!PhotonNetwork.isNonMasterClientInRoom)
			{
				Area area = AreaManager.Instance.GetArea(town.Area);
				Plugin.Log.LogInfo((object)("Teleporting to " + town.Name + " (" + area.SceneName + ")"));
				NetworkLevelLoader.Instance.RequestSwitchArea(area.SceneName, 0, 1.5f, true);
			}
		}
	}

	private static Town Find(int teleportID)
	{
		return Towns.All.FirstOrDefault((Town t) => t.TeleportID == teleportID);
	}
}
internal static class Passives
{
	public static void Refresh()
	{
		if (!SL.PacksLoaded || !Object.op_Implicit((Object)(object)CharacterManager.Instance) || NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			return;
		}
		foreach (Character item in Rules.Players())
		{
			if (item.IsLocalPlayer && Object.op_Implicit((Object)(object)item.Stats) && !((Object)(object)item.Inventory == (Object)null))
			{
				Town[] all = Towns.All;
				foreach (Town town in all)
				{
					Set(item, town, ((CharacterKnowledge)item.Inventory.SkillKnowledge).IsItemLearned(town.PassiveID));
				}
			}
		}
	}

	private static void Set(Character character, Town town, bool learned)
	{
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		CharacterStats stats = character.Stats;
		string text = "TeleportTrainer_" + town.Perk;
		switch (town.Perk)
		{
		case Perk.Pouch:
			FlatBonus(stats, "PouchCapacity", text, town.PerkValue, learned);
			break;
		case Perk.MaxMana:
			FlatBonus(stats, "MaxMana", text, town.PerkValue, learned);
			break;
		case Perk.DecayResistance:
			FlatBonus(stats, "DecayResistance", text, town.PerkValue, learned);
			break;
		case Perk.HeatDefence:
			FlatBonus(stats, "EnvHeatProtection", text, town.PerkValue, learned);
			break;
		case Perk.SprintCost:
		{
			object field = At.GetField<CharacterStats>(stats, "m_staminaUseModifiers");
			Stat val = (Stat)((field is Stat) ? field : null);
			if (val != null)
			{
				val.RemoveMultiplierStack(text);
				if (learned)
				{
					val.AddMultiplierStack(text, town.PerkValue, TagSourceManager.Sprint);
				}
			}
			break;
		}
		}
	}

	private static void FlatBonus(CharacterStats stats, string tagName, string source, float value, bool learned)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		Tag tag = CustomTags.GetTag(tagName, true);
		if (!(tag == Tag.None))
		{
			stats.RemoveStatStack(tag, source, false);
			if (learned)
			{
				stats.AddStatStack(tag, new StatStack(source, value, (Tag[])null), false);
			}
		}
	}
}
[BepInPlugin("aurai.wayfarers", "Wayfarers of Aurai", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "aurai.wayfarers";

	public const string NAME = "Wayfarers of Aurai";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	internal static ConfigEntry<float> ManaCost;

	internal static ConfigEntry<float> FatigueSeconds;

	internal static ConfigEntry<float> DrawTime;

	internal static ConfigEntry<int> TeleportPrice;

	internal static ConfigEntry<int> PassivePrice;

	private Trainers trainers;

	private float nextPassiveCheck;

	internal void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		ManaCost = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "ManaCost", 25f, "Mana per successful teleport.");
		FatigueSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "FatigueSeconds", 300f, "Length of Wayfarer's Fatigue.");
		DrawTime = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "DrawTime", 3.5f, "Seconds taken to draw the circle.");
		TeleportPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "TeleportSilver", 500, "Silver price of each teleport.");
		PassivePrice = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "PassiveSilver", 100, "Silver price of each passive.");
		trainers = new Trainers(((BaseUnityPlugin)this).Config);
		Network.Create();
		Skills.Register();
		Fatigue.Register();
		SL.OnPacksLoaded += OnPacksLoaded;
		SL.OnSceneLoaded += OnSceneLoaded;
		SL.OnGameplayResumedAfterLoading += Fatigue.ApplyPending;
		SL.OnGameplayResumedAfterLoading += Fatigue.ResetClock;
	}

	private void OnPacksLoaded()
	{
		Skills.Finish();
		trainers.Register();
	}

	private void OnSceneLoaded()
	{
		TeleportCircle.Clear();
		Fatigue.ResetClock();
		((MonoBehaviour)this).StartCoroutine(trainers.SpawnForScene());
	}

	internal void Update()
	{
		trainers?.CheckMoveHotkey((MonoBehaviour)(object)this);
		if (Time.unscaledTime >= nextPassiveCheck)
		{
			nextPassiveCheck = Time.unscaledTime + 2f;
			Passives.Refresh();
			Fatigue.Watch();
		}
	}
}
internal static class Rules
{
	public const float SoloRadius = 1.6f;

	public const float PartyRadius = 3f;

	public static List<Character> Players()
	{
		List<Character> list = new List<Character>();
		foreach (string value in CharacterManager.Instance.PlayerCharacters.Values)
		{
			Character character = CharacterManager.Instance.GetCharacter(value);
			if (Object.op_Implicit((Object)(object)character))
			{
				list.Add(character);
			}
		}
		return list;
	}

	public static float RadiusFor()
	{
		if (Players().Count <= 1)
		{
			return 1.6f;
		}
		return 3f;
	}

	public static string Problem(Character caster, Town town, Vector3 centre)
	{
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		if (SceneManagerHelper.ActiveSceneName == town.Scene)
		{
			return "You are already in " + town.Name + ".";
		}
		if (caster.Mana < Plugin.ManaCost.Value)
		{
			return $"You need {Plugin.ManaCost.Value} mana.";
		}
		if (caster.Inventory.ItemCount(town.ReagentID) < 1)
		{
			return "You need 1 " + town.ReagentName + ".";
		}
		List<Character> list = Players();
		if (list.All((Character p) => (Object)(object)p != (Object)(object)caster))
		{
			list.Add(caster);
		}
		float num = ((list.Count > 1) ? 3f : 1.6f);
		foreach (Character item in list)
		{
			bool flag = (Object)(object)item == (Object)(object)caster;
			string text = (flag ? "You are" : (item.Name + " is"));
			if (item.IsDead)
			{
				return text + " down.";
			}
			if (item.InCombat)
			{
				return text + " in combat.";
			}
			if (item.StatusEffectMngr.HasStatusEffect("WayfarersFatigue"))
			{
				return text + " still fatigued.";
			}
			if (!flag && Vector3.Distance(((Component)item).transform.position, centre) > num)
			{
				return item.Name + " must stand inside the circle.";
			}
		}
		return null;
	}
}
internal static class Skills
{
	private const int ActiveBaseID = 8200120;

	private const int PassiveBaseID = 8205030;

	public static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		Town[] all = Towns.All;
		foreach (Town town in all)
		{
			SL_Skill val = new SL_Skill();
			((SL_Item)val).Target_ItemID = 8200120;
			((SL_Item)val).New_ItemID = town.TeleportID;
			((SL_Item)val).Name = town.Name + " Teleport";
			((SL_Item)val).Description = "Draw a circle of power and travel to " + town.Name + ".\n" + $"Costs {Plugin.ManaCost.Value} mana and 1 {town.ReagentName} on arrival. " + "Companions must stand inside the circle. Causes Wayfarer's Fatigue.";
			val.Cooldown = 1f;
			val.ManaCost = 0f;
			val.StaminaCost = 0f;
			val.HealthCost = 0f;
			val.RequiredItems = (SkillItemReq[])(object)new SkillItemReq[1]
			{
				new SkillItemReq
				{
					ItemID = town.ReagentID,
					Quantity = 1,
					Consume = false
				}
			};
			((SL_Item)val).EffectBehaviour = (EditBehaviours)2;
			((SL_Item)val).EffectTransforms = (SL_EffectTransform[])(object)new SL_EffectTransform[1]
			{
				new SL_EffectTransform
				{
					TransformName = "Effects",
					Effects = (SL_Effect[])(object)new SL_Effect[0]
				}
			};
			((ContentTemplate)val).ApplyTemplate();
			((ContentTemplate)new SL_Skill
			{
				Target_ItemID = 8205030,
				New_ItemID = town.PassiveID,
				Name = town.PassiveName,
				Description = town.PassiveText,
				EffectBehaviour = (EditBehaviours)2
			}).ApplyTemplate();
		}
	}

	public static void Finish()
	{
		Town[] all = Towns.All;
		foreach (Town town in all)
		{
			Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(town.TeleportID);
			Skill val = (Skill)(object)((itemPrefab is Skill) ? itemPrefab : null);
			Transform val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).transform.Find("Effects") : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Component)val2).gameObject.AddComponent<TeleportEffect>().ItemID = town.TeleportID;
				SetIcons((Item)(object)val, town.TeleportID);
			}
			else
			{
				Plugin.Log.LogError((object)("Could not set up " + town.Name + " Teleport."));
			}
			Item itemPrefab2 = ResourcesPrefabManager.Instance.GetItemPrefab(town.PassiveID);
			Skill val3 = (Skill)(object)((itemPrefab2 is Skill) ? itemPrefab2 : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				SetIcons((Item)(object)val3, town.PassiveID);
			}
			else
			{
				Plugin.Log.LogError((object)("Could not set up " + town.PassiveName + "."));
			}
		}
	}

	private static void SetIcons(Item item, int id)
	{
		Sprite val = Icons.Load(id.ToString());
		if (Object.op_Implicit((Object)(object)val))
		{
			CustomItemVisuals.SetSpriteLink(item, val, false);
		}
		Sprite val2 = Icons.Load(id + "_small");
		if (Object.op_Implicit((Object)(object)val2))
		{
			CustomItemVisuals.SetSpriteLink(item, val2, true);
		}
	}
}
public class TeleportCircle : MonoBehaviour
{
	private const int Segments = 96;

	private const float MaxDrift = 0.6f;

	private static readonly Dictionary<string, TeleportCircle> Circles = new Dictionary<string, TeleportCircle>();

	private static float busyUntil;

	private string key;

	private bool isCaster;

	private Character caster;

	private Town town;

	private float radius;

	private Material material;

	private LineRenderer outer;

	private LineRenderer inner;

	private LineRenderer rising;

	public static bool Busy
	{
		get
		{
			if (!Circles.Values.Any((TeleportCircle c) => Object.op_Implicit((Object)(object)c) && c.isCaster))
			{
				return Time.unscaledTime < busyUntil;
			}
			return true;
		}
	}

	internal static void Begin(Character caster, Town town, Vector3 centre, float radius, bool isCaster)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		string casterUID = ((object)caster.UID/*cast due to .constrained prefix*/).ToString();
		Remove(casterUID);
		GameObject val = new GameObject("TeleportCircle");
		val.transform.position = centre;
		TeleportCircle teleportCircle = val.AddComponent<TeleportCircle>();
		teleportCircle.key = casterUID;
		teleportCircle.caster = caster;
		teleportCircle.town = town;
		teleportCircle.radius = radius;
		teleportCircle.isCaster = isCaster;
		Circles[casterUID] = teleportCircle;
		((MonoBehaviour)teleportCircle).StartCoroutine(teleportCircle.Cast());
	}

	internal static void Remove(string casterUID)
	{
		if (Circles.TryGetValue(casterUID, out var value))
		{
			Circles.Remove(casterUID);
			if (Object.op_Implicit((Object)(object)value))
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}
	}

	internal static void Clear()
	{
		foreach (string item in Circles.Keys.ToList())
		{
			Remove(item);
		}
		busyUntil = 0f;
	}

	private IEnumerator Cast()
	{
		Shader val = Shader.Find("Sprites/Default");
		if (!Object.op_Implicit((Object)(object)val))
		{
			val = Shader.Find("Legacy Shaders/Particles/Additive");
		}
		material = new Material(val);
		CastSound.Play(((Component)this).transform);
		outer = MakeLine("Outer", 0.09f);
		inner = MakeLine("Inner", 0.05f);
		rising = MakeLine("Rising", 0.06f);
		Vector3 centre = ((Component)this).transform.position + Vector3.up * 0.12f;
		float duration = Mathf.Max(0.5f, Plugin.DrawTime.Value);
		Dictionary<Character, float> health = (isCaster ? Rules.Players().ToDictionary((Character p) => p, (Character p) => p.Stats.CurrentHealth) : new Dictionary<Character, float>());
		for (float t = 0f; t < duration; t += Time.deltaTime)
		{
			if (isCaster && Broken(health))
			{
				yield break;
			}
			float num = t / duration;
			float fraction = Mathf.Clamp01(num / 0.75f);
			DrawArc(outer, centre, radius, fraction, 1f);
			DrawArc(inner, centre, radius * 0.75f, fraction, -1f);
			float num2 = Mathf.Clamp01((num - 0.75f) / 0.25f);
			((Renderer)rising).enabled = num2 > 0f;
			if (((Renderer)rising).enabled)
			{
				DrawArc(rising, centre + Vector3.up * (num2 * 2.2f), radius, 1f, 1f);
			}
			yield return null;
		}
		if (isCaster)
		{
			if (Broken(health))
			{
				yield break;
			}
			caster.Stats.UseMana((Tag[])(object)new Tag[0], Plugin.ManaCost.Value);
			caster.Inventory.RemoveItem(town.ReagentID, 1);
			busyUntil = Time.unscaledTime + 10f;
			Network.Instance.Travel(town);
		}
		Remove(key);
	}

	private bool Broken(Dictionary<Character, float> startHealth)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		string text = ((!Object.op_Implicit((Object)(object)caster)) ? "The circle fades." : ((Vector3.Distance(((Component)caster).transform.position, ((Component)this).transform.position) > 0.6f) ? "You left the circle." : ((!startHealth.Any((KeyValuePair<Character, float> p) => Object.op_Implicit((Object)(object)p.Key) && p.Key.Stats.CurrentHealth < p.Value - 1f)) ? Rules.Problem(caster, town, ((Component)this).transform.position) : "Concentration was broken by damage.")));
		if (text == null)
		{
			return false;
		}
		TeleportEffect.Notify(caster, text);
		Network.Instance.HideCircle(key);
		Remove(key);
		return true;
	}

	private LineRenderer MakeLine(string name, float width)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(((Component)this).transform, false);
		LineRenderer obj = val.AddComponent<LineRenderer>();
		obj.useWorldSpace = true;
		((Renderer)obj).sharedMaterial = material;
		float startWidth = (obj.endWidth = width);
		obj.startWidth = startWidth;
		Color startColor = (obj.endColor = town.Colour);
		obj.startColor = startColor;
		obj.positionCount = 0;
		return obj;
	}

	private static void DrawArc(LineRenderer line, Vector3 centre, float radius, float fraction, float direction)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		int num = (line.positionCount = Mathf.Max(2, Mathf.CeilToInt(96f * fraction) + 1));
		for (int i = 0; i < num; i++)
		{
			float num3 = direction * fraction * (float)Math.PI * 2f * (float)i / (float)(num - 1);
			line.SetPosition(i, centre + new Vector3(Mathf.Sin(num3), 0f, Mathf.Cos(num3)) * radius);
		}
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)material))
		{
			Object.Destroy((Object)(object)material);
		}
	}
}
public class TeleportEffect : Effect
{
	public int ItemID;

	public override void ActivateLocally(Character _affectedCharacter, object[] _infos)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)_affectedCharacter) || !_affectedCharacter.IsLocalPlayer)
		{
			return;
		}
		Town town = Towns.All.FirstOrDefault((Town t) => t.TeleportID == ItemID);
		if (town == null)
		{
			return;
		}
		if (TeleportCircle.Busy)
		{
			Notify(_affectedCharacter, "A teleport is already being cast.");
			return;
		}
		string text = Rules.Problem(_affectedCharacter, town, ((Component)_affectedCharacter).transform.position);
		if (text != null)
		{
			Notify(_affectedCharacter, text);
			return;
		}
		float radius = Rules.RadiusFor();
		TeleportCircle.Begin(_affectedCharacter, town, ((Component)_affectedCharacter).transform.position, radius, isCaster: true);
		Network.Instance.ShowCircle(_affectedCharacter, town, radius);
	}

	internal static void Notify(Character character, string message)
	{
		if (Object.op_Implicit((Object)(object)character) && Object.op_Implicit((Object)(object)character.CharacterUI))
		{
			character.CharacterUI.ShowInfoNotification(message);
		}
	}
}
internal enum Perk
{
	Pouch,
	SprintCost,
	DecayResistance,
	HeatDefence,
	MaxMana,
	ShorterFatigue
}
internal class Town
{
	public string Name;

	public string Scene;

	public AreaEnum Area;

	public Color Colour;

	public int TeleportID;

	public int ReagentID;

	public string ReagentName;

	public int PassiveID;

	public string PassiveName;

	public string PassiveText;

	public Perk Perk;

	public float PerkValue;

	public string Trainer;

	public string Greeting;

	public int RobeID;

	public int HatID;

	public VisualData Looks;

	public Vector3? Position;

	public float Facing;
}
internal static class Towns
{
	public static readonly Town[] All = new Town[6]
	{
		new Town
		{
			Name = "Cierzo",
			Scene = "CierzoNewTerrain",
			Area = (AreaEnum)100,
			Colour = new Color(0.3f, 0.7f, 1f),
			TeleportID = -27501,
			ReagentID = 6000060,
			ReagentName = "Seaweed",
			PassiveID = -27511,
			PassiveName = "Deep Pockets",
			PassiveText = "+2 pouch capacity.",
			Perk = Perk.Pouch,
			PerkValue = 2f,
			Trainer = "Kieran The Wayfarer",
			Greeting = "Every long road starts at the shore. Shall I teach you the way home?",
			RobeID = 3000270,
			HatID = 3000303,
			Looks = Look((Gender)0, 1, 8, 0),
			Position = new Vector3(1385.8f, 7.81f, 1651.17f),
			Facing = 247.9f
		},
		new Town
		{
			Name = "Berg",
			Scene = "Berg",
			Area = (AreaEnum)500,
			Colour = new Color(0.4f, 1f, 0.4f),
			TeleportID = -27502,
			ReagentID = 4000240,
			ReagentName = "Woolshroom",
			PassiveID = -27512,
			PassiveName = "Forest Strider",
			PassiveText = "Sprinting uses 10% less stamina.",
			Perk = Perk.SprintCost,
			PerkValue = -0.1f,
			Trainer = "Rowan The Wayfarer",
			Greeting = "The forest has short cuts, if you know how to draw them.",
			RobeID = 3000040,
			HatID = 3000133,
			Looks = Look((Gender)1, 2, 2, 2),
			Position = new Vector3(1202.05f, -13.72f, 1372.82f),
			Facing = 19.1f
		},
		new Town
		{
			Name = "Monsoon",
			Scene = "Monsoon",
			Area = (AreaEnum)200,
			Colour = new Color(0.6f, 0.4f, 1f),
			TeleportID = -27503,
			ReagentID = 4000190,
			ReagentName = "Marshmelon",
			PassiveID = -27513,
			PassiveName = "Marsh Ward",
			PassiveText = "+8% decay resistance.",
			Perk = Perk.DecayResistance,
			PerkValue = 8f,
			Trainer = "Isolde The Wayfarer",
			Greeting = "Walk the marsh long enough and you will wish to skip it.",
			RobeID = 3000260,
			HatID = 3000063,
			Looks = Look((Gender)1, 3, 7, 3),
			Position = new Vector3(145.15f, 9.04f, 241.66f),
			Facing = 129f
		},
		new Town
		{
			Name = "Levant",
			Scene = "Levant",
			Area = (AreaEnum)300,
			Colour = new Color(1f, 0.7f, 0.2f),
			TeleportID = -27504,
			ReagentID = 4000200,
			ReagentName = "Cactus Fruit",
			PassiveID = -27514,
			PassiveName = "Desert Walker",
			PassiveText = "+6 hot weather defence.",
			Perk = Perk.HeatDefence,
			PerkValue = 6f,
			Trainer = "Samir The Wayfarer",
			Greeting = "Why cross the sand twice? Let me show you the circle.",
			RobeID = 3000190,
			HatID = 3000191,
			Looks = Look((Gender)0, 4, 9, 1),
			Position = new Vector3(-110.46f, 5.25f, 48.98f),
			Facing = 92.5f
		},
		new Town
		{
			Name = "Harmattan",
			Scene = "Harmattan",
			Area = (AreaEnum)400,
			Colour = new Color(1f, 0.35f, 0.25f),
			TeleportID = -27505,
			ReagentID = 4000300,
			ReagentName = "Purpkin",
			PassiveID = -27515,
			PassiveName = "Leyline Echo",
			PassiveText = "+10 maximum mana.",
			Perk = Perk.MaxMana,
			PerkValue = 10f,
			Trainer = "Orrin The Wayfarer",
			Greeting = "In a city of magic, only amateurs still walk everywhere.",
			RobeID = 3000350,
			HatID = 3000071,
			Looks = Look((Gender)0, 5, 4, 0),
			Position = new Vector3(103.29f, 65.92f, 829.27f),
			Facing = 181.9f
		},
		new Town
		{
			Name = "New Sirocco",
			Scene = "NewSirocco",
			Area = (AreaEnum)601,
			Colour = new Color(1f, 0.9f, 0.5f),
			TeleportID = -27506,
			ReagentID = 4000390,
			ReagentName = "Rainbow Peach",
			PassiveID = -27516,
			PassiveName = "Seasoned Traveller",
			PassiveText = "Wayfarer's Fatigue lasts 25% less time.",
			Perk = Perk.ShorterFatigue,
			PerkValue = 0.75f,
			Trainer = "Nadia The Wayfarer",
			Greeting = "New town, old magic. The tired traveller learns this first.",
			RobeID = 3000340,
			HatID = 3000061,
			Looks = Look((Gender)1, 1, 5, 5),
			Position = new Vector3(57.05f, 55.9f, -61.87f),
			Facing = 20.6f
		}
	};

	private static VisualData Look(Gender gender, int head, int hair, int hairColour)
	{
		//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_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		return new VisualData
		{
			Gender = gender,
			SkinIndex = 0,
			HeadVariationIndex = head,
			HairStyleIndex = hair,
			HairColorIndex = hairColour
		};
	}
}
internal class Trainers
{
	private class Entry
	{
		public Town Town;

		public SL_CharacterTrainer Template;

		public ConfigEntry<bool> Placed;

		public ConfigEntry<Vector3> Position;

		public ConfigEntry<float> Facing;

		public string UID => "aurai.wayfarers.npc." + Town.Scene;
	}

	private readonly ConfigFile config;

	private readonly ConfigEntry<KeyboardShortcut> moveKey;

	private readonly List<Entry> entries = new List<Entry>();

	public Trainers(ConfigFile config)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		this.config = config;
		moveKey = config.Bind<KeyboardShortcut>("Trainers", "MoveHereKey", new KeyboardShortcut((KeyCode)289, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Moves this town's trainer to where you are standing.");
		Town[] all = Towns.All;
		foreach (Town town in all)
		{
			string text = "Trainer " + town.Name;
			entries.Add(new Entry
			{
				Town = town,
				Placed = config.Bind<bool>(text, "Placed", town.Position.HasValue, "False: pick a spot on the next visit."),
				Position = config.Bind<Vector3>(text, "Position", (Vector3)(((??)town.Position) ?? Vector3.zero), "World position."),
				Facing = config.Bind<float>(text, "Facing", town.Facing, "Rotation in degrees.")
			});
		}
	}

	public void Register()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		//IL_00d0: Expected O, but got Unknown
		//IL_00d6: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: 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_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Expected O, but got Unknown
		foreach (Entry entry in entries)
		{
			Town town = entry.Town;
			SL_SkillTree skillTree = new SL_SkillTree
			{
				Name = town.Name + " Wayfaring",
				UID = "aurai.wayfarers.tree." + town.Scene,
				SkillRows = new List<SL_SkillRow>
				{
					new SL_SkillRow
					{
						RowIndex = 1,
						Slots = new List<SL_BaseSkillSlot>
						{
							(SL_BaseSkillSlot)new SL_SkillSlot
							{
								ColumnIndex = 1,
								SkillID = town.TeleportID,
								SilverCost = Plugin.TeleportPrice.Value
							},
							(SL_BaseSkillSlot)new SL_SkillSlot
							{
								ColumnIndex = 3,
								SkillID = town.PassiveID,
								SilverCost = Plugin.PassivePrice.Value
							}
						}
					}
				}
			};
			entry.Template = new SL_CharacterTrainer
			{
				UID = entry.UID,
				Name = town.Trainer,
				SaveType = (CharSaveType)0,
				Faction = (Factions)0,
				CharacterVisualsData = town.Looks,
				Chest_ID = town.RobeID,
				Helmet_ID = town.HatID,
				SkillTree = skillTree,
				InitialDialogue = town.Greeting
			};
			((ContentTemplate)entry.Template).ApplyTemplate();
		}
	}

	private Entry Current()
	{
		return entries.FirstOrDefault((Entry e) => e.Town.Scene == SceneManagerHelper.ActiveSceneName);
	}

	public IEnumerator SpawnForScene()
	{
		Entry entry = Current();
		if (entry?.Template != null && !PhotonNetwork.isNonMasterClientInRoom)
		{
			while (NetworkLevelLoader.Instance.IsGameplayPaused)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(1f);
			if (Current() == entry && (entry.Placed.Value || TryPlaceNearPlayer(entry)))
			{
				Spawn(entry);
			}
		}
	}

	private static void Spawn(Entry entry)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = entry.Position.Value;
		NavMeshHit val2 = default(NavMeshHit);
		if (NavMesh.SamplePosition(val, ref val2, 3f, -1))
		{
			val = ((NavMeshHit)(ref val2)).position;
		}
		Plugin.Log.LogInfo((object)$"Spawning {entry.Town.Trainer} at {val} (saved {entry.Position.Value})");
		((SL_Character)entry.Template).Spawn(val, new Vector3(0f, entry.Facing.Value, 0f), entry.UID, (string)null);
	}

	private bool TryPlaceNearPlayer(Entry entry)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		Character firstLocalCharacter = CharacterManager.Instance.GetFirstLocalCharacter();
		if (!Object.op_Implicit((Object)(object)firstLocalCharacter) || ((Component)firstLocalCharacter).transform.position.y < -1000f)
		{
			return false;
		}
		Vector3 position = ((Component)firstLocalCharacter).transform.position;
		NavMeshHit val = default(NavMeshHit);
		for (int i = 0; i < 8; i++)
		{
			if (NavMesh.SamplePosition(position + Quaternion.Euler(0f, (float)i * 45f, 0f) * ((Component)firstLocalCharacter).transform.forward * 3.5f, ref val, 1.5f, -1) && Mathf.Abs(((NavMeshHit)(ref val)).position.y - position.y) < 1f && Vector3.Distance(((NavMeshHit)(ref val)).position, position) > 2f)
			{
				Vector3 val2 = position - ((NavMeshHit)(ref val)).position;
				Save(entry, ((NavMeshHit)(ref val)).position, Mathf.Atan2(val2.x, val2.z) * 57.29578f);
				TeleportEffect.Notify(firstLocalCharacter, entry.Town.Trainer + " is nearby.");
				return true;
			}
		}
		return false;
	}

	private void Save(Entry entry, Vector3 position, float facing)
	{
		//IL_0006: 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)
		entry.Position.Value = position;
		entry.Facing.Value = facing;
		entry.Placed.Value = true;
		config.Save();
		Plugin.Log.LogInfo((object)$"{entry.Town.Trainer} placed in {entry.Town.Scene} at {position}");
	}

	public void CheckMoveHotkey(MonoBehaviour host)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = moveKey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown() && !PhotonNetwork.isNonMasterClientInRoom)
		{
			Entry entry = Current();
			Character val = (Object.op_Implicit((Object)(object)CharacterManager.Instance) ? CharacterManager.Instance.GetFirstLocalCharacter() : null);
			if (entry?.Template != null && Object.op_Implicit((Object)(object)val))
			{
				Save(entry, ((Component)val).transform.position, (((Component)val).transform.eulerAngles.y + 180f) % 360f);
				host.StartCoroutine(Respawn(entry, val));
			}
		}
	}

	private IEnumerator Respawn(Entry entry, Character player)
	{
		if (Object.op_Implicit((Object)(object)CharacterManager.Instance.GetCharacter(entry.UID)))
		{
			CustomCharacters.DestroyCharacterRPC(entry.UID);
			yield return (object)new WaitForSeconds(1.5f);
		}
		if (Current() == entry)
		{
			Spawn(entry);
			TeleportEffect.Notify(player, entry.Town.Trainer + " moved here. Step back.");
		}
	}
}