Decompiled source of ScoutsMap v0.4.2

plugins/ScoutsMap.dll

Decompiled 40 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using SuperFantasyKingdom;
using SuperFantasyKingdom.Buildings;
using SuperFantasyKingdom.Clickable;
using SuperFantasyKingdom.Spawner;
using SuperFantasyKingdom.Spells;
using SuperFantasyKingdom.UI;
using SuperFantasyKingdom.Weather;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Localization;
using UnityEngine.Tilemaps;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScoutsMap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.2.0")]
[assembly: AssemblyInformationalVersion("0.4.2+a17e466ca230849a645aaa8461770eed61095d6e")]
[assembly: AssemblyProduct("ScoutsMap")]
[assembly: AssemblyTitle("ScoutsMap")]
[assembly: AssemblyVersion("0.4.2.0")]
namespace ScoutsMap;

internal static class EncounterTargets
{
	private enum ProvokeBlock
	{
		None,
		AlreadyProvoked,
		BossDead,
		AfterWork,
		Rush,
		Unknown
	}

	private static readonly FieldRef<WorldSpell, SpellType> SpellId = Field<WorldSpell, SpellType>("m_SpellType");

	private static readonly FieldRef<WorldSpell, LocalizedString> SpellError = Field<WorldSpell, LocalizedString>("stringError");

	private static readonly FieldRef<WorldMonster, LocalizedString> ProvokeAnother = Field<WorldMonster, LocalizedString>("provokeAnother");

	private static readonly FieldRef<WorldMonster, LocalizedString> ProvokeImpossible = Field<WorldMonster, LocalizedString>("provokeImpossible");

	private static readonly FieldRef<WorldMonster, LocalizedString> ProvokeDay = Field<WorldMonster, LocalizedString>("provokeDay");

	private static readonly FieldRef<WorldMonster, LocalizedString> ProvokeRush = Field<WorldMonster, LocalizedString>("provokeRush");

	private static readonly FieldRef<WorldRelic, string> RelicOffer = Field<WorldRelic, string>("m_Relic");

	private static readonly FieldRef<WorldItem, string> ItemOffer = Field<WorldItem, string>("m_Relic");

	private static readonly FieldRef<DropRelic, string> RelicDrop = Field<DropRelic, string>("m_Identifier");

	private static readonly FieldRef<DropUnit, string> UnitDrop = Field<DropUnit, string>("m_Unit");

	private static readonly FieldRef<WorldUnit, string> UnitOffer = Field<WorldUnit, string>("m_UnitIdentifier");

	private static readonly FieldRef<WorldUnit, LocalizedString> UnitError = Field<WorldUnit, LocalizedString>("stringError");

	private static readonly FieldRef<WorldHero, string> HeroId = Field<WorldHero, string>("m_Hero");

	private static readonly FieldRef<WorldHero, int> HeroKills = Field<WorldHero, int>("m_Kills");

	private static readonly FieldRef<WorldHero, int> HeroRequired = Field<WorldHero, int>("m_Required");

	private static readonly FieldRef<WorldHero, LocalizedString> HeroError = Field<WorldHero, LocalizedString>("stringRequired");

	private static readonly FieldRef<Trap, string> Captured = Field<Trap, string>("m_Captured");

	private static readonly FieldRef<BuildingWorldPirates, int> PirateReturn = Field<BuildingWorldPirates, int>("m_IsPlundering");

	private static readonly FieldRef<BuildingWorldWonder, bool> WonderPending = Field<BuildingWorldWonder, bool>("m_SpawnTomorrow");

	private static readonly FieldRef<BuildingWorldWonder, GameObject> WonderReady = Field<BuildingWorldWonder, GameObject>("question");

	private static readonly FieldRef<BuildingWorldWonder, ResourceAmount> WonderCost = Field<BuildingWorldWonder, ResourceAmount>("costs");

	private static readonly FieldRef<BuildingHospital, LocalizedString> HospitalError = Field<BuildingHospital, LocalizedString>("stringNoDead");

	private static readonly FieldRef<BuildingHospital, LocalizedString> HospitalTitle = Field<BuildingHospital, LocalizedString>("stringHospital");

	private static readonly FieldRef<BuildingTrade, ResourceAmount> TradeCost = Field<BuildingTrade, ResourceAmount>("cost");

	private static readonly FieldRef<WorldResource, ResourceType> Resource = Field<WorldResource, ResourceType>("resource");

	private static readonly FieldRef<Destroyable, RaceEvent> SalvageRequirement = Field<Destroyable, RaceEvent>("canUpgrade");

	private static readonly FieldRef<UnitQuest, string> CageUnit = Field<UnitQuest, string>("entityIdentifier");

	private static readonly FieldRef<UnitQuest, string> CageAchievement = Field<UnitQuest, string>("requiredAchievement");

	private static readonly FieldRef<UnitQuest, GameObject> CageHint = Field<UnitQuest, GameObject>("questionMark");

	private static readonly FieldRef<UnitQuest, GameObject> CageReadyIcon = Field<UnitQuest, GameObject>("exclamationMark");

	private static readonly Func<WorldUnit, int> RecruitPrice = AccessTools.MethodDelegate<Func<WorldUnit, int>>(AccessTools.DeclaredMethod(typeof(WorldUnit), "GetCoinCost", (Type[])null, (Type[])null), (object)null, true);

	private static readonly Func<BuildingHospital, int> RevivePrice = AccessTools.MethodDelegate<Func<BuildingHospital, int>>(AccessTools.DeclaredMethod(typeof(BuildingHospital), "GetCosts", (Type[])null, (Type[])null), (object)null, true);

	private static readonly Func<BuildingWorldPirates, ResourceAmount> PiratePrice = AccessTools.MethodDelegate<Func<BuildingWorldPirates, ResourceAmount>>(AccessTools.DeclaredMethod(typeof(BuildingWorldPirates), "GetCost", (Type[])null, (Type[])null), (object)null, true);

	private static FieldRef<T, F> Field<T, F>(string name)
	{
		return AccessTools.FieldRefAccess<T, F>(name);
	}

	internal static MarkerIcon? ForPickup(ClickableSprite target)
	{
		if (!(target is DropChest))
		{
			if (!(target is WorldHermit))
			{
				if (!(target is WorldRewardGiver))
				{
					if (!(target is WorldSpell))
					{
						if (!(target is WorldMonster))
						{
							if (!(target is Trap))
							{
								if (!(target is DropRelic) && !(target is WorldRelic))
								{
									if (!(target is WorldItem))
									{
										if (!(target is DropUnit) && !(target is WorldUnit))
										{
											if (!(target is WorldApple))
											{
												if (!(target is WorldSuperMetal))
												{
													WorldResource val = (WorldResource)(object)((target is WorldResource) ? target : null);
													if (val == null)
													{
														Destroyable val2 = (Destroyable)(object)((target is Destroyable) ? target : null);
														if (val2 != null && IsHighValueSalvage(val2))
														{
															return MarkerIcon.Salvage;
														}
													}
													else if ((int)Resource.Invoke(val) == 23)
													{
														return MarkerIcon.Rare;
													}
													return null;
												}
												return MarkerIcon.Rare;
											}
											return MarkerIcon.Apple;
										}
										return MarkerIcon.Recruit;
									}
									return MarkerIcon.Item;
								}
								return MarkerIcon.Relic;
							}
							return MarkerIcon.Capture;
						}
						return MarkerIcon.Provoke;
					}
					return MarkerIcon.Spell;
				}
				return MarkerIcon.Reward;
			}
			return MarkerIcon.Hermit;
		}
		return MarkerIcon.Treasure;
	}

	internal static MarkerIcon? ForSite(ClickableSprite target)
	{
		if (!(target is BuildingQuest) && !(target is BuildingBoard))
		{
			if (!(target is WorldHero))
			{
				if (!(target is BuildingWorldPirates))
				{
					if (!(target is BuildingWorldWonder))
					{
						if (!(target is BuildingWitch))
						{
							if (!(target is BuildingHospital))
							{
								if (!(target is BuildingTrade))
								{
									if (target is UnitQuest)
									{
										return MarkerIcon.Cage;
									}
									return WorldSites.ForSite(target);
								}
								return MarkerIcon.Trade;
							}
							return MarkerIcon.Hospital;
						}
						return MarkerIcon.Witch;
					}
					return MarkerIcon.Wonder;
				}
				return MarkerIcon.Pirate;
			}
			return MarkerIcon.Hero;
		}
		return MarkerIcon.Quest;
	}

	internal static bool IsQuestTurnIn(ClickableSprite target)
	{
		BuildingQuest val = (BuildingQuest)(object)((target is BuildingQuest) ? target : null);
		if (val == null)
		{
			BuildingBoard val2 = (BuildingBoard)(object)((target is BuildingBoard) ? target : null);
			if (val2 != null)
			{
				return val2.IsCityFinished() || val2.IsCombatFinished() || val2.IsDefenseFinished();
			}
			return false;
		}
		return !val.IsFinished() && (Object)(object)val.GetQuestTask() != (Object)null && val.GetQuestTask().IsDone();
	}

	internal static MarkerState Read(ClickableSprite target)
	{
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		BuildingQuest val = (BuildingQuest)(object)((target is BuildingQuest) ? target : null);
		if (val == null)
		{
			BuildingWorldPirates val2 = (BuildingWorldPirates)(object)((target is BuildingWorldPirates) ? target : null);
			if (val2 == null)
			{
				BuildingWorldWonder val3 = (BuildingWorldWonder)(object)((target is BuildingWorldWonder) ? target : null);
				if (val3 == null)
				{
					if (target is BuildingWitch)
					{
						if (RaceDataManager.Instance.GetBonfiresUnlocked() >= 4)
						{
							return MarkerState.Hidden;
						}
						if (RaceDataManager.Instance.GetStars() < WitchCost().amount)
						{
							return MarkerState.Cost;
						}
						return MarkerState.Available;
					}
					WorldSpell val4 = (WorldSpell)(object)((target is WorldSpell) ? target : null);
					if (val4 != null)
					{
						SpellBase spell = GetSpell(val4);
						if ((Object)(object)spell == (Object)null)
						{
							return MarkerState.Hidden;
						}
						if (!SpellManager.Instance.CanAddSpell(spell.IsCombatSpell()))
						{
							return MarkerState.Restricted;
						}
						return MarkerState.Available;
					}
					WorldMonster val5 = (WorldMonster)(object)((target is WorldMonster) ? target : null);
					if (val5 != null)
					{
						if (string.IsNullOrEmpty(val5.GetEntityType()))
						{
							return MarkerState.Hidden;
						}
						if (ProvokeRestriction() != ProvokeBlock.None)
						{
							return MarkerState.Restricted;
						}
						return MarkerState.Available;
					}
					Trap val6 = (Trap)(object)((target is Trap) ? target : null);
					if (val6 == null)
					{
						WorldItem val7 = (WorldItem)(object)((target is WorldItem) ? target : null);
						if (val7 == null)
						{
							WorldRelic val8 = (WorldRelic)(object)((target is WorldRelic) ? target : null);
							if (val8 == null)
							{
								WorldUnit val9 = (WorldUnit)(object)((target is WorldUnit) ? target : null);
								if (val9 == null)
								{
									WorldHero val10 = (WorldHero)(object)((target is WorldHero) ? target : null);
									if (val10 != null)
									{
										if ((Object)(object)GetHero(val10) == (Object)null)
										{
											return MarkerState.Hidden;
										}
										if (HeroKills.Invoke(val10) < HeroRequired.Invoke(val10))
										{
											return MarkerState.Restricted;
										}
										return MarkerState.Available;
									}
									if (!(target is BuildingHospital))
									{
										if (target is WorldApple)
										{
											if (!((Object)(object)UnitManager.Instance.GetLowestLevelUnit() != (Object)null))
											{
												return MarkerState.Restricted;
											}
											return MarkerState.Available;
										}
										UnitQuest val11 = (UnitQuest)(object)((target is UnitQuest) ? target : null);
										if (val11 != null)
										{
											PermanentDataManager instance = PermanentDataManager.Instance;
											string text = CageAchievement.Invoke(val11);
											if (string.IsNullOrEmpty(text) || instance.GetSolvedUnitQuests().Contains(text) || (!IsShowing(CageHint.Invoke(val11)) && !IsShowing(CageReadyIcon.Invoke(val11))))
											{
												return MarkerState.Hidden;
											}
											if (!instance.GetUnlockedAchievements().Contains(text))
											{
												return MarkerState.Restricted;
											}
											return MarkerState.Available;
										}
										Destroyable val12 = (Destroyable)(object)((target is Destroyable) ? target : null);
										if (val12 != null && SalvageRequirement.Invoke(val12) && !RaceDataManager.Instance.HasRaceEventFlag(SalvageRequirement.Invoke(val12)))
										{
											return MarkerState.Restricted;
										}
									}
									else if (!HasReviveTarget())
									{
										return MarkerState.Restricted;
									}
								}
								else
								{
									Unit unit = GetUnit(UnitOffer.Invoke(val9));
									if ((Object)(object)unit == (Object)null)
									{
										return MarkerState.Hidden;
									}
									if (!UnitManager.Instance.CanAddUnit((UnitBase)(object)unit, true, false))
									{
										return MarkerState.Restricted;
									}
								}
							}
							else if ((Object)(object)GetRelic(RelicOffer.Invoke(val8)) == (Object)null)
							{
								return MarkerState.Hidden;
							}
						}
						else if ((Object)(object)GetItem(val7) == (Object)null)
						{
							return MarkerState.Hidden;
						}
					}
					else if (string.IsNullOrEmpty(Captured.Invoke(val6)))
					{
						return MarkerState.Hidden;
					}
				}
				else if (WonderPending.Invoke(val3) && !IsShowing(WonderReady.Invoke(val3)))
				{
					return MarkerState.Hidden;
				}
			}
			else
			{
				int num = DaytimeManager.Instance.CurrentDay();
				if (PirateReturn.Invoke(val2) > num || num <= 1 || !RaceDataManager.Instance.HasRaceEventFlag((RaceEvent)181))
				{
					return MarkerState.Hidden;
				}
			}
		}
		else
		{
			if (val.IsFinished() || (Object)(object)val.GetQuestTask() == (Object)null || val.GetReward() == null)
			{
				return MarkerState.Hidden;
			}
			BuildingDungeon val13 = (BuildingDungeon)(object)((val is BuildingDungeon) ? val : null);
			if (val13 != null && DungeonRestriction(val13) != null)
			{
				return MarkerState.Restricted;
			}
		}
		ResourceAmount val14 = Cost(target);
		if ((int)val14.type != 0 && !ResourceManager.Instance.CanBeBuilt(val14))
		{
			return MarkerState.Cost;
		}
		return MarkerState.Available;
	}

	internal static (string Title, string Reason) Describe(ClickableSprite target, MarkerState state)
	{
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		BuildingQuest val = (BuildingQuest)(object)((target is BuildingQuest) ? target : null);
		string text;
		if (val == null)
		{
			if (!(target is BuildingBoard))
			{
				WorldSpell val2 = (WorldSpell)(object)((target is WorldSpell) ? target : null);
				if (val2 == null)
				{
					WorldMonster val3 = (WorldMonster)(object)((target is WorldMonster) ? target : null);
					if (val3 == null)
					{
						Trap val4 = (Trap)(object)((target is Trap) ? target : null);
						if (val4 == null)
						{
							DropRelic val5 = (DropRelic)(object)((target is DropRelic) ? target : null);
							if (val5 == null)
							{
								WorldRelic val6 = (WorldRelic)(object)((target is WorldRelic) ? target : null);
								if (val6 == null)
								{
									WorldItem val7 = (WorldItem)(object)((target is WorldItem) ? target : null);
									if (val7 == null)
									{
										DropUnit val8 = (DropUnit)(object)((target is DropUnit) ? target : null);
										if (val8 == null)
										{
											WorldUnit val9 = (WorldUnit)(object)((target is WorldUnit) ? target : null);
											if (val9 == null)
											{
												WorldHero val10 = (WorldHero)(object)((target is WorldHero) ? target : null);
												if (val10 == null)
												{
													BuildingWorldPirates val11 = (BuildingWorldPirates)(object)((target is BuildingWorldPirates) ? target : null);
													if (val11 == null)
													{
														BuildingWorldWonder val12 = (BuildingWorldWonder)(object)((target is BuildingWorldWonder) ? target : null);
														if (val12 == null)
														{
															if (!(target is BuildingWitch))
															{
																BuildingHospital val13 = (BuildingHospital)(object)((target is BuildingHospital) ? target : null);
																if (val13 == null)
																{
																	BuildingTrade val14 = (BuildingTrade)(object)((target is BuildingTrade) ? target : null);
																	if (val14 == null)
																	{
																		if (!(target is WorldApple))
																		{
																			if (!(target is WorldSuperMetal))
																			{
																				if (!(target is WorldResource))
																				{
																					UnitQuest val15 = (UnitQuest)(object)((target is UnitQuest) ? target : null);
																					if (val15 != null)
																					{
																						Unit unit = GetUnit(CageUnit.Invoke(val15));
																						text = ((unit != null) ? ((Entity)unit).GetName(true) : null) ?? "Unit cage";
																					}
																					else
																					{
																						text = "Coastal salvage";
																					}
																				}
																				else
																				{
																					text = "Shards";
																				}
																			}
																			else
																			{
																				text = "Super Metal";
																			}
																		}
																		else
																		{
																			text = "XP apple";
																		}
																	}
																	else
																	{
																		text = (((Object)val14).name.StartsWith("TradeAlchemist", StringComparison.Ordinal) ? "Alchemist" : "Resource trade");
																	}
																}
																else
																{
																	text = Localize(HospitalTitle.Invoke(val13), "Hospital");
																}
															}
															else
															{
																text = "Witch’s bonfire";
															}
														}
														else
														{
															text = (WonderPending.Invoke(val12) ? "Wonder reward" : "Wonder");
														}
													}
													else
													{
														text = ((PirateReturn.Invoke(val11) > 0) ? "Pirate return" : "Pirate expedition");
													}
												}
												else
												{
													Hero hero = GetHero(val10);
													text = ((hero != null) ? ((Entity)hero).GetName(true) : null) ?? "Hero encounter";
												}
											}
											else
											{
												Unit unit2 = GetUnit(UnitOffer.Invoke(val9));
												text = ((unit2 != null) ? ((Entity)unit2).GetName(true) : null) ?? "Recruitable unit";
											}
										}
										else
										{
											Unit unit3 = GetUnit(UnitDrop.Invoke(val8));
											text = ((unit3 != null) ? ((Entity)unit3).GetName(true) : null) ?? "Unit reward";
										}
									}
									else
									{
										Item item = GetItem(val7);
										text = ((item != null) ? item.GetTitle() : null) ?? "Item offer";
									}
								}
								else
								{
									Relic relic = GetRelic(RelicOffer.Invoke(val6));
									text = ((relic != null) ? ((Item)relic).GetTitle() : null) ?? "Relic offer";
								}
							}
							else
							{
								Relic relic2 = GetRelic(RelicDrop.Invoke(val5));
								text = ((relic2 != null) ? ((Item)relic2).GetTitle() : null) ?? "Dropped relic";
							}
						}
						else
						{
							Unit unit4 = GetUnit(Captured.Invoke(val4));
							text = ((unit4 != null) ? ((Entity)unit4).GetName(true) : null) ?? "Captured monster";
						}
					}
					else
					{
						Unit unit5 = GetUnit(val3.GetEntityType());
						text = ((unit5 != null) ? ((Entity)unit5).GetName(true) : null) ?? "Monster";
					}
				}
				else
				{
					SpellBase spell = GetSpell(val2);
					text = ((spell != null) ? spell.GetTitle() : null) ?? "Spell pickup";
				}
			}
			else
			{
				text = "Quest board";
			}
		}
		else
		{
			text = ((BuildingWorld)val).GetTitle();
		}
		string item2 = text;
		if (state == MarkerState.Restricted)
		{
			return (Title: item2, Reason: Restriction(target));
		}
		ResourceAmount val16 = Cost(target);
		if ((int)val16.type != 0)
		{
			return (Title: item2, Reason: FormatCost(val16, state == MarkerState.Cost));
		}
		BuildingQuest val17 = (BuildingQuest)(object)((target is BuildingQuest) ? target : null);
		if (val17 == null)
		{
			BuildingBoard val18 = (BuildingBoard)(object)((target is BuildingBoard) ? target : null);
			if (val18 == null)
			{
				if (!(target is BuildingWorldPirates))
				{
					if (!(target is BuildingWorldWonder))
					{
						if (!(target is Trap))
						{
							WorldMonster val19 = (WorldMonster)(object)((target is WorldMonster) ? target : null);
							text = ((val19 != null) ? $"Provoke (level {val19.GetLevel()})" : ((target is WorldHero) ? "Ready to unlock" : ((!(target is UnitQuest)) ? null : "Achievement complete")));
						}
						else
						{
							text = "Ready to collect";
						}
					}
					else
					{
						text = "Ready to collect";
					}
				}
				else
				{
					text = "Ready to collect";
				}
			}
			else
			{
				text = (IsQuestTurnIn((ClickableSprite)(object)val18) ? "Ready to turn in" : "Open objectives");
			}
		}
		else
		{
			text = (IsQuestTurnIn((ClickableSprite)(object)val17) ? "Ready to turn in" : QuestProgress(val17));
		}
		string item3 = text;
		return (Title: item2, Reason: item3);
	}

	private static string Restriction(ClickableSprite target)
	{
		WorldSpell val = (WorldSpell)(object)((target is WorldSpell) ? target : null);
		if (val == null)
		{
			WorldMonster val2 = (WorldMonster)(object)((target is WorldMonster) ? target : null);
			if (val2 == null)
			{
				WorldUnit val3 = (WorldUnit)(object)((target is WorldUnit) ? target : null);
				if (val3 == null)
				{
					WorldHero val4 = (WorldHero)(object)((target is WorldHero) ? target : null);
					if (val4 == null)
					{
						BuildingHospital val5 = (BuildingHospital)(object)((target is BuildingHospital) ? target : null);
						if (val5 == null)
						{
							BuildingDungeon val6 = (BuildingDungeon)(object)((target is BuildingDungeon) ? target : null);
							if (val6 == null)
							{
								if (!(target is WorldApple))
								{
									if (target is UnitQuest)
									{
										return "Complete the unit’s achievement";
									}
									return "A discovery requirement is still unmet";
								}
								return "No unit can gain experience";
							}
							return DungeonRestriction(val6);
						}
						return Localize(HospitalError.Invoke(val5), "No unit can be revived");
					}
					int num = HeroRequired.Invoke(val4) - HeroKills.Invoke(val4);
					LocalizedString val7 = HeroError.Invoke(val4);
					if (val7 != null && !((LocalizedReference)val7).IsEmpty)
					{
						object[] obj = new object[2] { num, null };
						Hero hero = GetHero(val4);
						obj[1] = ((hero != null) ? ((Entity)hero).GetName(true) : null) ?? "Hero";
						return val7.GetLocalizedString(obj);
					}
					return $"Defeat {num} more enemies";
				}
				Unit unit = GetUnit(UnitOffer.Invoke(val3));
				string text = ((unit != null) ? ((Entity)unit).GetName(true) : null) ?? "unit";
				LocalizedString val8 = UnitError.Invoke(val3);
				if (val8 != null && !((LocalizedReference)val8).IsEmpty)
				{
					return val8.GetLocalizedString(new object[1] { text });
				}
				return "This unit cannot join your roster";
			}
			return ProvokeRestriction() switch
			{
				ProvokeBlock.AlreadyProvoked => Localize(ProvokeAnother.Invoke(val2), "Another monster is already provoked"), 
				ProvokeBlock.BossDead => Localize(ProvokeImpossible.Invoke(val2), "Provocation is unavailable"), 
				ProvokeBlock.AfterWork => Localize(ProvokeDay.Invoke(val2), "Provoke during work hours"), 
				ProvokeBlock.Rush => Localize(ProvokeRush.Invoke(val2), "Unavailable during a glory rush"), 
				_ => "Provocation is unavailable", 
			};
		}
		return Localize(SpellError.Invoke(val), "No spell slot available");
	}

	private static ResourceAmount Cost(ClickableSprite target)
	{
		//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_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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		WorldItem val = (WorldItem)(object)((target is WorldItem) ? target : null);
		if (val == null)
		{
			WorldRelic val2 = (WorldRelic)(object)((target is WorldRelic) ? target : null);
			if (val2 == null)
			{
				WorldUnit val3 = (WorldUnit)(object)((target is WorldUnit) ? target : null);
				if (val3 == null)
				{
					BuildingHospital val4 = (BuildingHospital)(object)((target is BuildingHospital) ? target : null);
					if (val4 == null)
					{
						BuildingTrade val5 = (BuildingTrade)(object)((target is BuildingTrade) ? target : null);
						if (val5 == null)
						{
							BuildingWorldPirates val6 = (BuildingWorldPirates)(object)((target is BuildingWorldPirates) ? target : null);
							if (val6 == null)
							{
								BuildingWorldWonder val7 = (BuildingWorldWonder)(object)((target is BuildingWorldWonder) ? target : null);
								if (val7 == null)
								{
									if (target is BuildingWitch)
									{
										return WitchCost();
									}
									if (target is WorldSuperMetal)
									{
										return new ResourceAmount((ResourceType)23, 12);
									}
								}
								else if (!WonderPending.Invoke(val7))
								{
									return WonderCost.Invoke(val7);
								}
							}
							else if (PirateReturn.Invoke(val6) <= 0)
							{
								return PiratePrice(val6);
							}
							return default(ResourceAmount);
						}
						return TradeCost.Invoke(val5);
					}
					return new ResourceAmount((ResourceType)12, RevivePrice(val4));
				}
				return new ResourceAmount((ResourceType)12, RecruitPrice(val3));
			}
			Relic relic = GetRelic(RelicOffer.Invoke(val2));
			return new ResourceAmount((ResourceType)13, (relic != null) ? ((Item)relic).GetCost() : 0);
		}
		Item item = GetItem(val);
		return new ResourceAmount((ResourceType)13, (item != null) ? item.GetCost() : 0);
	}

	private static ResourceAmount WitchCost()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		return new ResourceAmount((ResourceType)54, RaceDataManager.Instance.GetBonfiresUnlocked() + 12);
	}

	private static string QuestProgress(BuildingQuest quest)
	{
		float progressPercentage = quest.GetProgressPercentage();
		if (!float.IsNaN(progressPercentage) && !float.IsInfinity(progressPercentage))
		{
			return $"Quest in progress · {Mathf.FloorToInt(Mathf.Clamp01(progressPercentage) * 100f)}%";
		}
		return "Open quest";
	}

	private static string DungeonRestriction(BuildingDungeon dungeon)
	{
		DaytimeManager instance = DaytimeManager.Instance;
		int num = instance.CurrentDay();
		if (instance.IsNight())
		{
			return "Unavailable at night";
		}
		if (num == 28 && !instance.IsMorningOrLoading())
		{
			return "Available in the morning";
		}
		if (IsQuestTurnIn((ClickableSprite)(object)dungeon))
		{
			return null;
		}
		if (num == 29)
		{
			return "Unavailable on the final day";
		}
		if (dungeon.GetUnit() > 0)
		{
			if (!dungeon.IsInDaHouse())
			{
				return "Expedition starts tomorrow";
			}
			return "Expedition in progress";
		}
		if (!WorldManager.Instance.IsDungeonPlaned())
		{
			return null;
		}
		return "Another expedition is planned";
	}

	internal unsafe static string FormatCost(ResourceAmount price, bool blocked)
	{
		//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_0054: 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)
		ResourceData resourceData = RaceManager.Instance.GetResourceData(price.type);
		string arg = (((Object)(object)resourceData != (Object)null) ? resourceData.GetName() : ((object)(*(ResourceType*)(&price.type))/*cast due to .constrained prefix*/).ToString());
		if (!blocked)
		{
			return $"{price.amount} {arg}";
		}
		return $"Requires {price.amount} {arg}";
	}

	private static bool HasReviveTarget()
	{
		UnitBase[] allUnits = UnitManager.Instance.GetAllUnits();
		foreach (UnitBase val in allUnits)
		{
			if ((Object)(object)val != (Object)null && val.IsDead() && !val.IsHero() && val.HasRanks() && val.GetGridPosition() >= 0 && val.GetGridPosition() != 98 && val.GetGridPosition() != 99)
			{
				return true;
			}
		}
		return false;
	}

	private static bool IsHighValueSalvage(Destroyable target)
	{
		if (!((Object)target).name.StartsWith("DestroyableFloatsamChest", StringComparison.Ordinal) && !((Object)target).name.StartsWith("DestroyableFloatsamShards", StringComparison.Ordinal))
		{
			return ((Object)target).name.StartsWith("DestroyableSuperMetal", StringComparison.Ordinal);
		}
		return true;
	}

	private static bool IsShowing(GameObject indicator)
	{
		if ((Object)(object)indicator != (Object)null)
		{
			return indicator.activeInHierarchy;
		}
		return false;
	}

	private static ProvokeBlock ProvokeRestriction()
	{
		if ((Object)(object)ProvokedSpawner.Instance == (Object)null || (Object)(object)BossSpawner.Instance == (Object)null || (Object)(object)MonsterSpawner.Instance == (Object)null)
		{
			return ProvokeBlock.Unknown;
		}
		if (ProvokedSpawner.Instance.IsProvoked())
		{
			return ProvokeBlock.AlreadyProvoked;
		}
		if (BossSpawner.Instance.IsBossDead())
		{
			return ProvokeBlock.BossDead;
		}
		if (!DaytimeManager.Instance.IsWorkTime())
		{
			return ProvokeBlock.AfterWork;
		}
		if (DaytimeManager.Instance.IsMorningOrLoading() || !(MonsterSpawner.Instance.GetBonusGlory() > 0f))
		{
			return ProvokeBlock.None;
		}
		return ProvokeBlock.Rush;
	}

	internal static Sprite GetSymbol(ClickableSprite target)
	{
		WorldMonster val = (WorldMonster)(object)((target is WorldMonster) ? target : null);
		if (val == null)
		{
			WorldSpell val2 = (WorldSpell)(object)((target is WorldSpell) ? target : null);
			if (val2 == null)
			{
				Trap val3 = (Trap)(object)((target is Trap) ? target : null);
				if (val3 == null)
				{
					DropRelic val4 = (DropRelic)(object)((target is DropRelic) ? target : null);
					if (val4 == null)
					{
						WorldRelic val5 = (WorldRelic)(object)((target is WorldRelic) ? target : null);
						if (val5 == null)
						{
							WorldItem val6 = (WorldItem)(object)((target is WorldItem) ? target : null);
							if (val6 == null)
							{
								DropUnit val7 = (DropUnit)(object)((target is DropUnit) ? target : null);
								if (val7 == null)
								{
									WorldUnit val8 = (WorldUnit)(object)((target is WorldUnit) ? target : null);
									if (val8 == null)
									{
										WorldHero val9 = (WorldHero)(object)((target is WorldHero) ? target : null);
										if (val9 == null)
										{
											UnitQuest val10 = (UnitQuest)(object)((target is UnitQuest) ? target : null);
											if (val10 != null)
											{
												Unit unit = GetUnit(CageUnit.Invoke(val10));
												return (unit != null) ? ((Entity)unit).GetIcon() : null;
											}
											return null;
										}
										Hero hero = GetHero(val9);
										return (hero != null) ? ((Entity)hero).GetIcon() : null;
									}
									Unit unit2 = GetUnit(UnitOffer.Invoke(val8));
									return (unit2 != null) ? ((Entity)unit2).GetIcon() : null;
								}
								Unit unit3 = GetUnit(UnitDrop.Invoke(val7));
								return (unit3 != null) ? ((Entity)unit3).GetIcon() : null;
							}
							Item item = GetItem(val6);
							return (item != null) ? item.GetIcon() : null;
						}
						Relic relic = GetRelic(RelicOffer.Invoke(val5));
						return (relic != null) ? ((Item)relic).GetIcon() : null;
					}
					Relic relic2 = GetRelic(RelicDrop.Invoke(val4));
					return (relic2 != null) ? ((Item)relic2).GetIcon() : null;
				}
				Unit unit4 = GetUnit(Captured.Invoke(val3));
				return (unit4 != null) ? ((Entity)unit4).GetIcon() : null;
			}
			SpellBase spell = GetSpell(val2);
			return (spell != null) ? spell.GetIcon() : null;
		}
		Unit unit5 = GetUnit(val.GetEntityType());
		return (unit5 != null) ? ((Entity)unit5).GetIcon() : null;
	}

	private static SpellBase GetSpell(WorldSpell target)
	{
		return SpellManager.Instance.GetSpell(SpellId.Invoke(target));
	}

	private static Item GetItem(WorldItem target)
	{
		if (!string.IsNullOrEmpty(ItemOffer.Invoke(target)))
		{
			return AddressablesManager.Instance.GetItem(ItemOffer.Invoke(target));
		}
		return null;
	}

	private static Unit GetUnit(string id)
	{
		if (!string.IsNullOrEmpty(id))
		{
			return AddressablesManager.Instance.GetUnit(id);
		}
		return null;
	}

	private static Relic GetRelic(string id)
	{
		if (!string.IsNullOrEmpty(id))
		{
			return AddressablesManager.Instance.GetRelic(id);
		}
		return null;
	}

	private static Hero GetHero(WorldHero target)
	{
		if (!string.IsNullOrEmpty(HeroId.Invoke(target)))
		{
			return AddressablesManager.Instance.GetHero(HeroId.Invoke(target));
		}
		return null;
	}

	private static string Localize(LocalizedString text, string fallback)
	{
		if (text != null && !((LocalizedReference)text).IsEmpty)
		{
			return text.GetLocalizedString();
		}
		return fallback;
	}
}
internal enum MarkerIcon
{
	Treasure,
	Hermit,
	Reward,
	Road,
	City,
	Water,
	Shop,
	Quest,
	Spell,
	Capture,
	Relic,
	Item,
	Recruit,
	Hero,
	Pirate,
	Wonder,
	Witch,
	Hospital,
	Trade,
	Apple,
	Rare,
	Cage,
	Salvage,
	Provoke,
	Restore,
	TradingPost,
	Site
}
internal sealed class MarkerArt : IDisposable
{
	private enum FrameType
	{
		Route,
		Shop,
		Site,
		Person,
		Loot,
		Magic,
		Monster
	}

	private readonly List<Sprite> sprites = new List<Sprite>();

	private readonly List<Texture2D> textures = new List<Texture2D>();

	internal readonly Sprite Arrow;

	internal readonly Sprite Lock;

	internal readonly Sprite Panel;

	private readonly (Sprite Plate, Sprite Rim, Sprite InteractionEdge, Color32 Accent)[] frames = new(Sprite, Sprite, Sprite, Color32)[Enum.GetValues(typeof(FrameType)).Length];

	private readonly Sprite[,] symbols = new Sprite[Enum.GetValues(typeof(MarkerIcon)).Length, 2];

	internal MarkerArt()
	{
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0491: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0641: Unknown result type (might be due to invalid IL or missing references)
		//IL_0654: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_075a: Unknown result type (might be due to invalid IL or missing references)
		//IL_076d: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_086a: Unknown result type (might be due to invalid IL or missing references)
		//IL_087d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_096d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0980: Unknown result type (might be due to invalid IL or missing references)
		//IL_09f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a03: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a73: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a86: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b06: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b6d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b7d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bfd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c73: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c86: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cf3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d06: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d76: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d86: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e02: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e15: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e8b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e9e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0f05: Unknown result type (might be due to invalid IL or missing references)
		//IL_0f15: Unknown result type (might be due to invalid IL or missing references)
		//IL_0f79: Unknown result type (might be due to invalid IL or missing references)
		//IL_0f89: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ff3: Unknown result type (might be due to invalid IL or missing references)
		//IL_1006: Unknown result type (might be due to invalid IL or missing references)
		//IL_1073: Unknown result type (might be due to invalid IL or missing references)
		//IL_1086: Unknown result type (might be due to invalid IL or missing references)
		Color32 highlight = default(Color32);
		((Color32)(ref highlight))..ctor(byte.MaxValue, (byte)250, (byte)225, byte.MaxValue);
		string[] rows = new string[16]
		{
			"..oooooooooooo..", ".obbbbbbbbbbbbo.", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo",
			"obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", "obbbbbbbbbbbbbbo", ".obbbbbbbbbbbbo.", "..oooooooooooo.."
		};
		Panel = Draw(Color32.op_Implicit(Color.white), new Color32((byte)42, (byte)31, (byte)33, byte.MaxValue), highlight, Vector4.one * 4f, rows);
		AddFrame(FrameType.Route, new Color32((byte)226, (byte)194, (byte)146, byte.MaxValue), new Color32((byte)51, (byte)41, (byte)36, byte.MaxValue), 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12);
		AddFrame(FrameType.Shop, new Color32(byte.MaxValue, (byte)177, (byte)105, byte.MaxValue), new Color32((byte)70, (byte)36, (byte)29, byte.MaxValue), 10, 12, 14, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14);
		AddFrame(FrameType.Site, new Color32((byte)143, (byte)216, (byte)192, byte.MaxValue), new Color32((byte)27, (byte)58, (byte)55, byte.MaxValue), 8, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16);
		AddFrame(FrameType.Person, new Color32((byte)166, (byte)202, (byte)253, byte.MaxValue), new Color32((byte)32, (byte)43, (byte)69, byte.MaxValue), 10, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, 8, 4);
		AddFrame(FrameType.Loot, new Color32((byte)251, (byte)211, (byte)110, byte.MaxValue), new Color32((byte)56, (byte)43, (byte)26, byte.MaxValue), 8, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 8);
		AddFrame(FrameType.Magic, new Color32((byte)215, (byte)173, (byte)251, byte.MaxValue), new Color32((byte)54, (byte)35, (byte)68, byte.MaxValue), 4, 8, 12, 14, 14, 16, 16, 16, 16, 16, 16, 14, 14, 12, 8, 4);
		AddFrame(FrameType.Monster, new Color32(byte.MaxValue, (byte)141, (byte)142, byte.MaxValue), new Color32((byte)72, (byte)35, (byte)44, byte.MaxValue), 6, 10, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, 6);
		Arrow = Draw(new Color32((byte)15, (byte)16, (byte)22, byte.MaxValue), Color32.op_Implicit(Color.clear), highlight, Vector4.zero, new string[7] { "o......", "o#o....", "o###o..", "o#####o", "o###o..", "o#o....", "o......" });
		Lock = Draw(new Color32((byte)15, (byte)16, (byte)22, byte.MaxValue), new Color32((byte)45, (byte)52, (byte)64, byte.MaxValue), highlight, Vector4.zero, new string[7] { "..ooo..", ".o###o.", ".o#.#o.", "o#####o", "o##b##o", "o##b##o", ".ooooo." });
		Add(MarkerIcon.Treasure, new Color32((byte)217, (byte)147, (byte)58, byte.MaxValue), new Color32((byte)126, (byte)60, (byte)42, byte.MaxValue), "..oooooooo..", ".o########o.", "o#+----+#++o", "o++----+++-o", "o##########o", "o--+###+---o", "o---+#+----o", "o---+#+----o", "o+++---++++o", ".oooooooooo.");
		Add(MarkerIcon.Hermit, new Color32((byte)138, (byte)176, (byte)98, byte.MaxValue), new Color32((byte)68, (byte)96, (byte)70, byte.MaxValue), "....oooo....", "...o+++-o...", "..o+#++--o..", ".o++#o+---o.", ".o++o##o--o.", ".o+o###o--o.", ".oo+#++-ooo.", ".o++#+----o.", "o++-------+o", ".oooooooooo.");
		Add(MarkerIcon.Reward, new Color32((byte)216, (byte)147, (byte)246, byte.MaxValue), new Color32((byte)134, (byte)70, (byte)183, byte.MaxValue), ".....o......", "....o#o.....", "...o##+o.o..", "..o##++ooo..", ".o##++---o..", "o#+++----+o.", ".o++----+o..", "..o+---+o...", "...o+++o....", "....o+o.....", ".....o......");
		Add(MarkerIcon.Road, new Color32((byte)213, (byte)172, (byte)114, byte.MaxValue), new Color32((byte)134, (byte)97, (byte)62, byte.MaxValue), "..oo....oo..", ".o##o..o##o.", ".o++#oo#++o.", "..o++##++o..", "...o++++o...", "...o+##-o...", "...o+---o...", "...o+##-o...", "...o+---o...", "...o++++o...", "....oooo....");
		Add(MarkerIcon.City, new Color32((byte)212, (byte)172, (byte)136, byte.MaxValue), new Color32((byte)138, (byte)93, (byte)79, byte.MaxValue), ".oo.oo.oo...", "o##o##o##o..", "o########o..", "o+------#o..", "o+-oooo-#o..", "o+o####o#o..", "o+o#..#o#o..", "o+o#..#o#o..", "o+o#..#o+o..", ".oo....oo...");
		Add(MarkerIcon.Water, new Color32((byte)101, (byte)202, (byte)224, byte.MaxValue), new Color32((byte)54, (byte)121, (byte)158, byte.MaxValue), ".....oo.....", ".....o#o....", ".....o++o...", "...o.o+--o..", "..o#.o+---o.", ".o#o.o++++oo", "oooooooooooo", "o+########+o", ".o--------o.", "..o++++++o..", "...oooooo...");
		Add(MarkerIcon.Shop, new Color32((byte)243, (byte)133, (byte)91, byte.MaxValue), new Color32((byte)152, (byte)68, (byte)52, byte.MaxValue), "..oooooooo..", ".o#++#++#+o.", "o##+##+##++o", "o++-++-++--o", ".oooooooooo.", ".o#++++++#o.", ".o+o####o+o.", ".o+o##o#o+o.", ".o+o####o+o.", ".oooooooooo.");
		Add(MarkerIcon.Quest, new Color32((byte)218, (byte)184, (byte)115, byte.MaxValue), new Color32((byte)134, (byte)96, (byte)64, byte.MaxValue), "..ooooooo.", "..o####oo.", "..o#+++o..", "..o###+o..", "..o++++o..", "..o###+o..", "..o++++o..", ".oo++++o..", "o#######o.", ".ooooooo..");
		Add(MarkerIcon.Spell, new Color32((byte)121, (byte)169, (byte)247, byte.MaxValue), new Color32((byte)61, (byte)94, (byte)163, byte.MaxValue), ".....o....", "....o#o.o.", "..o.o##oo.", "...oo#+o..", "..o##+o...", "...oo+o...", ".oo#oo....", "o##o......", "oooo......");
		Add(MarkerIcon.Capture, new Color32((byte)143, (byte)199, (byte)129, byte.MaxValue), new Color32((byte)59, (byte)108, (byte)77, byte.MaxValue), "...oooo...", "..o#..#o..", ".oo++++oo.", "o########o", "o#o+o+o#o.", "o#o#o#o#o.", "o#o#o#o#o.", "o++++++++o", ".oooooooo.");
		Add(MarkerIcon.Relic, new Color32((byte)217, (byte)159, (byte)240, byte.MaxValue), new Color32((byte)122, (byte)74, (byte)171, byte.MaxValue), "..oooooo..", ".o######o.", "o###++###o", "o##+--+##o", ".o++##++o.", "..o####o..", "...o##o...", "...o++o...", "....oo....");
		Add(MarkerIcon.Item, new Color32((byte)152, (byte)204, (byte)225, byte.MaxValue), new Color32((byte)65, (byte)110, (byte)139, byte.MaxValue), "...oooo...", "...o##o...", "...o##o...", "..oo++oo..", ".o##+++oo.", "o##+++++-o", "o#++#+++-o", "o+--+---+o", ".oooooooo.");
		Add(MarkerIcon.Recruit, new Color32((byte)177, (byte)189, (byte)217, byte.MaxValue), new Color32((byte)83, (byte)102, (byte)139, byte.MaxValue), "...oooo...", "..o####o..", ".o##++++o.", "o##++++--o", "o#+o++o+-o", "o#++++++-o", ".o++##++o.", "..o++++o..", "...oooo...");
		Add(MarkerIcon.Hero, new Color32((byte)238, (byte)179, (byte)94, byte.MaxValue), new Color32((byte)163, (byte)94, (byte)50, byte.MaxValue), "o....o...o", "o#..o#o.#o", "o#oo#++o#o", "o###+#++#o", "o++#+++#+o", ".o++++++o.", ".o######o.", "..oooooo..");
		Add(MarkerIcon.Pirate, new Color32((byte)196, (byte)203, (byte)200, byte.MaxValue), new Color32((byte)89, (byte)109, (byte)107, byte.MaxValue), "..ooooooo.", "..o#####oo", "..o#o#o#o.", "..o#####oo", "..o++o++o.", "..ooooooo.", "..o.......", "..o.......", ".ooo......");
		Add(MarkerIcon.Wonder, new Color32((byte)239, (byte)186, (byte)115, byte.MaxValue), new Color32((byte)147, (byte)85, (byte)83, byte.MaxValue), "....oo....", "...o##o...", "..o####o..", ".o######o.", "o+######+o", "oooo+oooo.", ".o+#++#+o.", ".o+#++#+o.", "o########o", "oooooooooo");
		Add(MarkerIcon.Witch, new Color32((byte)247, (byte)140, (byte)93, byte.MaxValue), new Color32((byte)169, (byte)60, (byte)61, byte.MaxValue), "....o.....", "...o#o....", "...o#+o...", "..o###+o..", ".o##+++-o.", "o###o++--o", "o+###+---o", ".o++++++o.", "..oooooo..");
		Add(MarkerIcon.Hospital, new Color32((byte)228, (byte)129, (byte)125, byte.MaxValue), new Color32((byte)151, (byte)57, (byte)78, byte.MaxValue), "..oo..oo..", ".o##oo##o.", "o########o", "o###++###o", "o#++++++#o", ".o##++##o.", "..o####o..", "...o##o...", "....oo....");
		Add(MarkerIcon.Trade, new Color32((byte)145, (byte)210, (byte)186, byte.MaxValue), new Color32((byte)58, (byte)124, (byte)122, byte.MaxValue), "......o...", ".....o#o..", ".ooooo##o.", "o#######oo", ".ooooo##o.", "..o..o#o..", ".o#o..o...", "o##oooooo.", "oo#######o", ".o##ooooo.", "..oo......");
		Add(MarkerIcon.Apple, new Color32((byte)235, (byte)125, (byte)94, byte.MaxValue), new Color32((byte)147, (byte)53, (byte)49, byte.MaxValue), ".....oo...", "....o++o..", "....o#o...", "..ooo#oo..", ".o##+##+o.", "o##+++++-o", "o#+++++--o", "o+++++---o", ".o++-+++o.", "..oooooo..");
		Add(MarkerIcon.Rare, new Color32((byte)115, (byte)212, (byte)228, byte.MaxValue), new Color32((byte)58, (byte)113, (byte)163, byte.MaxValue), "...oooo...", "..o####o..", ".o####+oo.", "o##++--#+o", "o#++--+#+o", ".o+--++#o.", "..o--+oo..", "...oooo...");
		Add(MarkerIcon.Cage, new Color32((byte)195, (byte)164, (byte)136, byte.MaxValue), new Color32((byte)98, (byte)78, (byte)83, byte.MaxValue), "...oooo...", "..o####o..", ".o++++++o.", "o#o#o#o#oo", "o#o#o#o#oo", "o#o#o#o#oo", "o#++++++oo", ".oooooooo.");
		Add(MarkerIcon.Salvage, new Color32((byte)209, (byte)158, (byte)102, byte.MaxValue), new Color32((byte)116, (byte)68, (byte)53, byte.MaxValue), "..oooooo..", ".o##++##o.", "o###++###o", "oooooooooo", "o++--+--+o", "o++--+--+o", "oooooooooo", ".o#+###+o.", "..oooooo..");
		Add(MarkerIcon.Provoke, new Color32((byte)226, (byte)112, (byte)103, byte.MaxValue), new Color32((byte)135, (byte)52, (byte)62, byte.MaxValue), "oo......oo", "o#o....o#o", "o#+oooo+#o", "o++++++++o", "o+#++++#+o", "o++----++o", ".o+####+o.", "..o+##+o..", "...oooo...");
		Add(MarkerIcon.Restore, new Color32((byte)219, (byte)172, (byte)101, byte.MaxValue), new Color32((byte)137, (byte)86, (byte)52, byte.MaxValue), "..ooooo...", ".o##+++oo.", "o##++++++o", ".oo+++++oo", "...o++oo..", "...o+-o...", "..o+-o....", ".o+-o.....", "o++o......", ".oo.......");
	}

	internal (Sprite Plate, Sprite Rim, Sprite InteractionEdge, Color32 Accent) Frame(MarkerIcon icon)
	{
		switch (icon)
		{
		case MarkerIcon.Road:
		case MarkerIcon.City:
		case MarkerIcon.Water:
			return frames[0];
		case MarkerIcon.Shop:
			return frames[1];
		case MarkerIcon.Quest:
		case MarkerIcon.Pirate:
		case MarkerIcon.Wonder:
		case MarkerIcon.Witch:
		case MarkerIcon.Hospital:
		case MarkerIcon.Trade:
		case MarkerIcon.Restore:
		case MarkerIcon.TradingPost:
		case MarkerIcon.Site:
			return frames[2];
		case MarkerIcon.Hermit:
		case MarkerIcon.Recruit:
		case MarkerIcon.Hero:
		case MarkerIcon.Cage:
			return frames[3];
		case MarkerIcon.Reward:
		case MarkerIcon.Spell:
		case MarkerIcon.Relic:
			return frames[5];
		case MarkerIcon.Capture:
		case MarkerIcon.Provoke:
			return frames[6];
		default:
			return frames[4];
		}
	}

	private void AddFrame(FrameType type, Color32 accent, Color32 body, params int[] widths)
	{
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: 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_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		bool[,] array = new bool[32, 32];
		for (int i = 0; i < 32; i++)
		{
			int num = (32 - 2 * widths[i / 2]) / 2;
			for (int j = num; j < 32 - num; j++)
			{
				array[i, j] = true;
			}
		}
		bool[,] array2 = Inset(array, 32);
		bool[,] array3 = Inset(array2, 32);
		bool[,] array4 = Inset(array3, 32);
		string[] array5 = new string[32];
		string[] array6 = new string[32];
		string[] array7 = new string[32];
		for (int k = 0; k < 32; k++)
		{
			char[] array8 = new char[32];
			char[] array9 = new char[32];
			char[] array10 = new char[32];
			for (int l = 0; l < 32; l++)
			{
				array8[l] = (array3[k, l] ? 'b' : (array[k, l] ? 'o' : '.'));
				array9[l] = ((array3[k, l] && !array4[k, l]) ? 'o' : '.');
				array10[l] = ((array[k, l] && !array2[k, l]) ? 'o' : '.');
			}
			array5[k] = new string(array8);
			array6[k] = new string(array9);
			array7[k] = new string(array10);
		}
		frames[(int)type] = (Plate: Draw(new Color32((byte)10, (byte)13, (byte)18, byte.MaxValue), body, Color32.op_Implicit(Color.white), Vector4.zero, array5), Rim: Draw(Color32.op_Implicit(Color.white), Color32.op_Implicit(Color.clear), Color32.op_Implicit(Color.white), Vector4.zero, array6), InteractionEdge: Draw(Color32.op_Implicit(Color.white), Color32.op_Implicit(Color.clear), Color32.op_Implicit(Color.white), Vector4.zero, array7), Accent: accent);
	}

	private static bool[,] Inset(bool[,] mask, int size)
	{
		bool[,] array = new bool[size, size];
		for (int i = 1; i < size - 1; i++)
		{
			for (int j = 1; j < size - 1; j++)
			{
				array[i, j] = mask[i, j] && mask[i - 1, j] && mask[i + 1, j] && mask[i, j - 1] && mask[i, j + 1];
			}
		}
		return array;
	}

	internal Sprite Symbol(MarkerIcon icon, bool available)
	{
		switch (icon)
		{
		case MarkerIcon.TradingPost:
			icon = MarkerIcon.Trade;
			break;
		case MarkerIcon.Site:
			icon = MarkerIcon.Quest;
			break;
		}
		return symbols[(int)icon, (!available) ? 1u : 0u];
	}

	private void Add(MarkerIcon icon, Color32 middle, Color32 shade, params string[] rows)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0051: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		Color32 outline = default(Color32);
		((Color32)(ref outline))..ctor((byte)16, (byte)18, (byte)23, byte.MaxValue);
		symbols[(int)icon, 0] = Draw(outline, middle, new Color32(byte.MaxValue, (byte)239, (byte)185, byte.MaxValue), Vector4.zero, rows, shade);
		symbols[(int)icon, 1] = Draw(outline, new Color32((byte)147, (byte)158, (byte)172, byte.MaxValue), new Color32((byte)208, (byte)216, (byte)221, byte.MaxValue), Vector4.zero, rows, new Color32((byte)81, (byte)95, (byte)111, byte.MaxValue));
	}

	private Sprite Draw(Color32 outline, Color32 body, Color32 highlight, Vector4 border, string[] rows, Color32 shade = default(Color32))
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00e9: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		int length = rows[0].Length;
		int num = rows.Length;
		Color32[] array = (Color32[])(object)new Color32[length * num];
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < length; j++)
			{
				Color32[] array2 = array;
				int num2 = (num - i - 1) * length + j;
				array2[num2] = (Color32)(rows[i][j] switch
				{
					'o' => outline, 
					'b' => body, 
					'+' => body, 
					'#' => highlight, 
					'-' => shade, 
					_ => Color32.op_Implicit(Color.clear), 
				});
			}
		}
		Texture2D val = new Texture2D(length, num, (TextureFormat)4, false)
		{
			filterMode = (FilterMode)0,
			wrapMode = (TextureWrapMode)1
		};
		val.SetPixels32(array);
		val.Apply(false, true);
		Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)length, (float)num), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, border);
		sprites.Add(val2);
		textures.Add(val);
		return val2;
	}

	public void Dispose()
	{
		foreach (Sprite sprite in sprites)
		{
			Object.Destroy((Object)(object)sprite);
		}
		foreach (Texture2D texture in textures)
		{
			Object.Destroy((Object)(object)texture);
		}
	}
}
internal sealed class MarkerBadge : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ICanvasRaycastFilter
{
	private static readonly Color32 DisabledRim = new Color32((byte)106, (byte)117, (byte)135, byte.MaxValue);

	private static readonly Color32 DisabledPlate = new Color32((byte)105, (byte)119, (byte)144, byte.MaxValue);

	private static readonly Color32 DisabledSymbol = new Color32((byte)190, (byte)201, (byte)213, byte.MaxValue);

	private Image plate;

	private Image rim;

	private Image interactionEdge;

	private Image symbol;

	private MarkerArt art;

	private Sprite entitySprite;

	private Color32 accent;

	private bool hasHover;

	private bool pressed;

	private Image arrow;

	private Image padlock;

	private Plugin owner;

	internal RectTransform Rect { get; private set; }

	internal MarkerTarget Target { get; private set; }

	internal MarkerState State { get; private set; }

	internal static MarkerBadge Create(Plugin owner, Transform parent, MarkerTarget target, MarkerArt art)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0096: 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_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Scout’s Map " + target.Kind, new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val.SetActive(false);
		Image component = val.GetComponent<Image>();
		(Sprite, Sprite, Sprite, Color32) tuple = art.Frame(target.Icon);
		component.sprite = tuple.Item1;
		val.transform.SetParent(parent, false);
		MarkerBadge markerBadge = val.AddComponent<MarkerBadge>();
		markerBadge.plate = component;
		markerBadge.Rect = ((Graphic)component).rectTransform;
		markerBadge.Rect.sizeDelta = Vector2.one * 32f;
		markerBadge.rim = Child(((Component)component).transform, "State outline", tuple.Item2, 32f);
		markerBadge.interactionEdge = Child(((Component)component).transform, "Interaction edge", tuple.Item3, 32f);
		((Behaviour)markerBadge.interactionEdge).enabled = false;
		markerBadge.entitySprite = target.EntitySprite;
		markerBadge.symbol = Child(((Component)component).transform, "Encounter", markerBadge.entitySprite ?? art.Symbol(target.Icon, available: true), 19f);
		markerBadge.accent = tuple.Item4;
		markerBadge.arrow = Child(((Component)component).transform, "Bearing", art.Arrow, 8f);
		markerBadge.padlock = Child(((Component)component).transform, "Unavailable", art.Lock, 9f);
		((Graphic)markerBadge.padlock).rectTransform.anchoredPosition = new Vector2(9f, -9f);
		markerBadge.Target = target;
		markerBadge.art = art;
		markerBadge.owner = owner;
		return markerBadge;
	}

	private static Image Child(Transform parent, string name, Sprite sprite, float size)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		Image component = new GameObject(name, new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		}).GetComponent<Image>();
		((Component)component).transform.SetParent(parent, false);
		((Graphic)component).rectTransform.sizeDelta = Vector2.one * size;
		component.sprite = sprite;
		component.preserveAspect = true;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	internal void Show(MarkerState state, Vector2 position, Vector2 bearing)
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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_0115: 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_012c: 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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		if (State != state)
		{
			State = state;
			bool flag = state == MarkerState.Available;
			if (!flag)
			{
				pressed = false;
			}
			((Graphic)plate).color = (flag ? Color.white : Color32.op_Implicit(DisabledPlate));
			((Graphic)symbol).color = (flag ? Color.white : Color32.op_Implicit(DisabledSymbol));
			symbol.sprite = (((Object)(object)entitySprite != (Object)null) ? entitySprite : art.Symbol(Target.Icon, flag));
			RefreshOutline();
			((Component)padlock).gameObject.SetActive(!flag);
		}
		Rect.anchoredPosition = position;
		((Vector2)(ref bearing)).Normalize();
		((Graphic)symbol).rectTransform.anchoredPosition = -bearing * 2f;
		((Graphic)arrow).rectTransform.anchoredPosition = bearing * 11.5f;
		((Transform)((Graphic)arrow).rectTransform).localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(bearing.y, bearing.x) * 57.29578f);
		if (!((Component)this).gameObject.activeSelf)
		{
			((Component)this).gameObject.SetActive(true);
		}
	}

	internal void SetHover(bool value)
	{
		if (hasHover != value || (!value && pressed))
		{
			hasHover = value;
			if (!value)
			{
				pressed = false;
			}
			RefreshOutline();
		}
	}

	private void RefreshOutline()
	{
		//IL_001b: 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_0020: 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)
		bool flag = State == MarkerState.Available;
		((Graphic)rim).color = Color32.op_Implicit(flag ? accent : DisabledRim);
		((Graphic)arrow).color = ((Graphic)rim).color;
		((Behaviour)interactionEdge).enabled = flag && (hasHover || pressed);
	}

	public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
	{
		if (!((Object)(object)GamepadManager.Instance == (Object)null))
		{
			return !GamepadManager.Instance.IsGamepadInUse();
		}
		return true;
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		//IL_0001: 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)
		if ((int)eventData.button == 0)
		{
			((AbstractEventData)eventData).Use();
			pressed = State == MarkerState.Available && IsRaycastLocationValid(eventData.position, eventData.pressEventCamera);
			RefreshOutline();
		}
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		if ((int)eventData.button == 0 && pressed)
		{
			pressed = false;
			RefreshOutline();
		}
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0001: 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)
		if ((int)eventData.button == 0 && IsRaycastLocationValid(eventData.position, eventData.pressEventCamera))
		{
			((AbstractEventData)eventData).Use();
			owner.Focus(Target);
		}
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		if (IsRaycastLocationValid(eventData.position, eventData.enterEventCamera))
		{
			owner.Hover(this);
		}
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		Leave();
	}

	private void OnDisable()
	{
		Leave();
	}

	private void Leave()
	{
		SetHover(value: false);
		owner.EndHover(this);
	}
}
internal enum MarkerGroup
{
	Expansions,
	Shops,
	Trades,
	OpenQuests,
	QuestTurnIns,
	Restoration,
	Services,
	Treasure,
	Encounters,
	Monsters,
	Recruiting,
	Magic,
	Rewards,
	RareFinds,
	UnitCages
}
internal sealed class MarkerGroups
{
	private readonly ConfigEntry<bool>[] entries = new ConfigEntry<bool>[Enum.GetValues(typeof(MarkerGroup)).Length];

	internal MarkerGroups(ConfigFile config)
	{
		ConfigFile config2 = config;
		base..ctor();
		MarkerGroups markerGroups = this;
		Bind(MarkerGroup.Expansions, "Road, city and water expansions.");
		Bind(MarkerGroup.Shops, "Markets, guild shops and merchant buildings.");
		Bind(MarkerGroup.Trades, "Trading Posts and resource exchanges.");
		Bind(MarkerGroup.OpenQuests, "Discovered unfinished quests and quest boards with open objectives.");
		Bind(MarkerGroup.QuestTurnIns, "Quest sites and quest boards with an objective ready to turn in.");
		Bind(MarkerGroup.Restoration, "Restorable plots, starting-resource sites and camps.");
		Bind(MarkerGroup.Services, "Guest callers, Witch bonfires, hospitals and other world services.");
		Bind(MarkerGroup.Treasure, "Treasure chests and item offers.");
		Bind(MarkerGroup.Encounters, "Hermits and capturable monsters.");
		Bind(MarkerGroup.Monsters, "Monsters available to provoke or temporarily blocked.");
		Bind(MarkerGroup.Recruiting, "Recruit, unit reward and hero encounters.");
		Bind(MarkerGroup.Magic, "Spells and relics.");
		Bind(MarkerGroup.Rewards, "World rewards, pirate expeditions and Wonders.");
		Bind(MarkerGroup.RareFinds, "XP apples, shards, Super Metal and high-value salvage.", enabled: false);
		Bind(MarkerGroup.UnitCages, "Discovered achievement-based unit cages.", enabled: false);
		void Bind(MarkerGroup group, string description, bool enabled = true)
		{
			entries[(int)group] = config2.Bind<bool>("Markers", group.ToString(), enabled, description);
		}
	}

	internal bool Enabled(MarkerGroup group)
	{
		return entries[(int)group].Value;
	}

	internal static MarkerGroup Get(MarkerIcon icon, bool questTurnIn)
	{
		switch (icon)
		{
		case MarkerIcon.Road:
			return MarkerGroup.Expansions;
		case MarkerIcon.Shop:
			return MarkerGroup.Shops;
		case MarkerIcon.Trade:
		case MarkerIcon.TradingPost:
			return MarkerGroup.Trades;
		case MarkerIcon.Quest:
			if (!questTurnIn)
			{
				return MarkerGroup.OpenQuests;
			}
			return MarkerGroup.QuestTurnIns;
		case MarkerIcon.Restore:
			return MarkerGroup.Restoration;
		case MarkerIcon.Treasure:
		case MarkerIcon.Item:
			return MarkerGroup.Treasure;
		case MarkerIcon.Hermit:
		case MarkerIcon.Capture:
			return MarkerGroup.Encounters;
		case MarkerIcon.Provoke:
			return MarkerGroup.Monsters;
		case MarkerIcon.Recruit:
		case MarkerIcon.Hero:
			return MarkerGroup.Recruiting;
		case MarkerIcon.Spell:
		case MarkerIcon.Relic:
			return MarkerGroup.Magic;
		case MarkerIcon.Reward:
		case MarkerIcon.Pirate:
		case MarkerIcon.Wonder:
			return MarkerGroup.Rewards;
		case MarkerIcon.Apple:
		case MarkerIcon.Rare:
		case MarkerIcon.Salvage:
			return MarkerGroup.RareFinds;
		case MarkerIcon.Cage:
			return MarkerGroup.UnitCages;
		default:
			return MarkerGroup.Services;
		}
	}
}
internal readonly struct MarkerPoint
{
	internal readonly float X;

	internal readonly float Y;

	internal MarkerPoint(float x, float y)
	{
		X = x;
		Y = y;
	}
}
internal readonly struct MarkerBounds
{
	internal readonly float Left;

	internal readonly float Bottom;

	internal readonly float Right;

	internal readonly float Top;

	internal MarkerBounds(float left, float bottom, float right, float top)
	{
		Left = left;
		Bottom = bottom;
		Right = right;
		Top = top;
	}
}
internal static class MarkerLayout
{
	internal const float BadgeSize = 32f;

	internal static bool TryPlaceAbove(MarkerBounds frame, MarkerPoint top, float scale, out MarkerPoint result)
	{
		float num = 32f * scale / 2f;
		result = new MarkerPoint(top.X, top.Y + num + 4f * scale);
		if (result.X - num >= frame.Left && result.X + num <= frame.Right && result.Y - num >= frame.Bottom)
		{
			return result.Y + num <= frame.Top;
		}
		return false;
	}

	internal static bool TryReserve(MarkerPoint candidate, float scale, List<MarkerPoint> occupied)
	{
		float num = 36f * scale;
		foreach (MarkerPoint item in occupied)
		{
			if (Math.Abs(item.X - candidate.X) < num && Math.Abs(item.Y - candidate.Y) < num)
			{
				return false;
			}
		}
		occupied.Add(candidate);
		return true;
	}

	internal static bool TryPlaceTooltip(MarkerBounds frame, MarkerPoint badge, float width, float height, float scale, IReadOnlyList<MarkerPoint> occupied, out MarkerPoint point)
	{
		point = default(MarkerPoint);
		float halfWidth = width / 2f;
		float halfHeight = height / 2f;
		float left = frame.Left + halfWidth;
		float right = frame.Right - halfWidth;
		float bottom = frame.Bottom + halfHeight;
		float top = frame.Top - halfHeight;
		if (left > right || bottom > top)
		{
			return false;
		}
		float num = 16f * scale;
		float num2 = num + 7f * scale;
		float clearance = num + 4f * scale;
		float num3 = (halfWidth + num2) * ((badge.X < (left + right) / 2f) ? 1f : (-1f));
		float num4 = (halfHeight + num2) * ((badge.Y < (bottom + top) / 2f) ? 1f : (-1f));
		for (int i = 0; i < 3; i++)
		{
			float num5 = ((i == 2) ? (-1f) : ((float)i));
			float x = Math.Clamp(badge.X + num5 * halfWidth, left, right);
			float y = Math.Clamp(badge.Y + num5 * halfHeight, bottom, top);
			if (TryAt(badge.X + num3, y, out point) || TryAt(badge.X - num3, y, out point) || TryAt(x, badge.Y + num4, out point) || TryAt(x, badge.Y - num4, out point))
			{
				return true;
			}
		}
		return false;
		bool TryAt(float num6, float num7, out MarkerPoint candidate)
		{
			candidate = default(MarkerPoint);
			if (num6 < left || num6 > right || num7 < bottom || num7 > top)
			{
				return false;
			}
			foreach (MarkerPoint item in occupied)
			{
				if (Math.Abs(num6 - item.X) < halfWidth + clearance && Math.Abs(num7 - item.Y) < halfHeight + clearance)
				{
					return false;
				}
			}
			candidate = new MarkerPoint(num6, num7);
			return true;
		}
	}

	internal static bool TryPlaceEdge(MarkerBounds frame, float targetX, float targetY, float centerX, float centerY, float scale, List<MarkerPoint> occupied, out MarkerPoint result)
	{
		result = default(MarkerPoint);
		float num = 32f * scale / 2f;
		float num2 = frame.Left + num;
		float num3 = frame.Right - num;
		float num4 = frame.Bottom + num;
		float num5 = frame.Top - num;
		if (num2 > num3 || num4 > num5)
		{
			return false;
		}
		float num6 = (num2 + num3) / 2f;
		float num7 = (num4 + num5) / 2f;
		float num8 = Math.Clamp(num6 + 1.2f * (targetX - centerX), num2, num3);
		float num9 = Math.Clamp(num7 + 1.2f * (targetY - centerY), num4, num5);
		bool flag = num8 == num2 || num8 == num3 || (num9 != num4 && num9 != num5 && Math.Abs(num8 - num6) > Math.Abs(num9 - num7));
		float num10 = 36f * scale;
		for (int i = 0; i <= occupied.Count * 2; i++)
		{
			float num11 = (float)((i + 1) / 2 * ((i % 2 != 0) ? 1 : (-1))) * num10;
			MarkerPoint markerPoint = (flag ? new MarkerPoint(num8, num9 + num11) : new MarkerPoint(num8 + num11, num9));
			if (!(markerPoint.X < num2) && !(markerPoint.X > num3) && !(markerPoint.Y < num4) && !(markerPoint.Y > num5) && TryReserve(markerPoint, scale, occupied))
			{
				result = markerPoint;
				return true;
			}
		}
		return false;
	}
}
internal enum MarkerState
{
	Hidden,
	Available,
	Setup,
	DayOne,
	Night,
	Glory,
	Level,
	Stars,
	Cost,
	Restricted
}
internal sealed class MarkerTarget
{
	private static readonly FieldRef<UIArrowRoad, string> RoadId = AccessTools.FieldRefAccess<UIArrowRoad, string>("m_RoadIdentifier");

	private static readonly FieldRef<UIArrowRoad, LocalizedString> TooLate = AccessTools.FieldRefAccess<UIArrowRoad, LocalizedString>("stringTooLate");

	private static readonly FieldRef<UIArrowRoad, LocalizedString> NeedGlory = AccessTools.FieldRefAccess<UIArrowRoad, LocalizedString>("stringNotEnoughGlory");

	private static readonly FieldRef<UIArrowRoad, LocalizedString> NeedLevel = AccessTools.FieldRefAccess<UIArrowRoad, LocalizedString>("stringNotEnoughKingdomLevel");

	private static readonly FieldRef<UIArrowRoad, LocalizedString> NeedStars = AccessTools.FieldRefAccess<UIArrowRoad, LocalizedString>("stringNotEnoughStars");

	private static readonly FieldRef<BuildingShop, int> ShopSetup = AccessTools.FieldRefAccess<BuildingShop, int>("daysToSetup");

	private static readonly FieldRef<BuildingObjectShop, int> ObjectShopSetup = AccessTools.FieldRefAccess<BuildingObjectShop, int>("daysToSetup");

	private static readonly FieldRef<BuildingGuildOld, int> GuildSetup = AccessTools.FieldRefAccess<BuildingGuildOld, int>("daysToSetup");

	private static readonly FieldRef<BuildingShop, SpriteRenderer> ShopCountdown = AccessTools.FieldRefAccess<BuildingShop, SpriteRenderer>("daysUntilWork");

	private static readonly FieldRef<BuildingObjectShop, SpriteRenderer> ObjectShopCountdown = AccessTools.FieldRefAccess<BuildingObjectShop, SpriteRenderer>("daysUntilWork");

	private static readonly FieldRef<BuildingGuildOld, SpriteRenderer> GuildCountdown = AccessTools.FieldRefAccess<BuildingGuildOld, SpriteRenderer>("daysUntilWork");

	private static readonly FieldRef<BuildingShop, LocalizedString> ShopTitle = AccessTools.FieldRefAccess<BuildingShop, LocalizedString>("stringTitle");

	private static readonly FieldRef<BuildingObjectShop, LocalizedString> ObjectShopTitle = AccessTools.FieldRefAccess<BuildingObjectShop, LocalizedString>("stringTitle");

	private static readonly FieldRef<BuildingGuildOld, LocalizedString> GuildTitle = AccessTools.FieldRefAccess<BuildingGuildOld, LocalizedString>("stringTitle");

	private static readonly FieldRef<BuildingGuildOld, LocalizedString> GuildFull = AccessTools.FieldRefAccess<BuildingGuildOld, LocalizedString>("stringError");

	private static readonly FieldRef<ClickableSprite, BoxCollider2D> TargetCollider = AccessTools.FieldRefAccess<ClickableSprite, BoxCollider2D>("boxCollider2D");

	private static readonly FieldRef<ClickableSprite, SpriteRenderer> TargetSprite = AccessTools.FieldRefAccess<ClickableSprite, SpriteRenderer>("spriteRenderer");

	internal readonly ClickableSprite Clickable;

	internal readonly MarkerIcon Kind;

	internal readonly int InstanceId;

	private readonly ClickableSprite interaction;

	private readonly UIArrowRoad roadArrow;

	private UIMarker nativeMarker;

	private Image nativeImage;

	private bool originalImageEnabled;

	private readonly Road road;

	internal MarkerBadge Badge;

	internal MarkerIcon Icon
	{
		get
		{
			if (Kind == MarkerIcon.Road)
			{
				if (road.city)
				{
					return MarkerIcon.City;
				}
				if ((Object)(object)road.pier != (Object)null)
				{
					return MarkerIcon.Water;
				}
			}
			return Kind;
		}
	}

	internal Vector3 Position => ((Component)Clickable).transform.position;

	internal Sprite EntitySprite
	{
		get
		{
			ClickableSprite clickable = Clickable;
			BuildingSpotWorld val = (BuildingSpotWorld)(object)((clickable is BuildingSpotWorld) ? clickable : null);
			if (val != null)
			{
				Sprite obj = WorldSites.RestoreIcon(val);
				if (obj == null)
				{
					SpriteRenderer spriteRenderer = SpriteRenderer;
					if (spriteRenderer == null)
					{
						return null;
					}
					obj = spriteRenderer.sprite;
				}
				return obj;
			}
			if ((Clickable is BuildingWorld && (Object)(object)roadArrow == (Object)null) || Clickable is BuildingBoard || Clickable is RepairableBuilding || Clickable is BuildingCloudColor)
			{
				SpriteRenderer spriteRenderer2 = SpriteRenderer;
				if (spriteRenderer2 == null)
				{
					return null;
				}
				return spriteRenderer2.sprite;
			}
			return EncounterTargets.GetSymbol(Clickable);
		}
	}

	internal bool NeedsNativeMarker { get; }

	internal bool Expired => (Object)(object)Clickable == (Object)null;

	internal bool IsQuestTurnIn => EncounterTargets.IsQuestTurnIn(Clickable);

	internal MarkerGroup Group => MarkerGroups.Get(Kind, Kind == MarkerIcon.Quest && IsQuestTurnIn);

	private SpriteRenderer SpriteRenderer
	{
		get
		{
			object obj = TargetSprite.Invoke(Clickable);
			if (obj == null)
			{
				if (!((Object)(object)interaction != (Object)null))
				{
					return null;
				}
				obj = TargetSprite.Invoke(interaction);
			}
			return (SpriteRenderer)obj;
		}
	}

	private int SetupDay
	{
		get
		{
			ClickableSprite clickable = Clickable;
			BuildingShop val = (BuildingShop)(object)((clickable is BuildingShop) ? clickable : null);
			if (val == null)
			{
				BuildingObjectShop val2 = (BuildingObjectShop)(object)((clickable is BuildingObjectShop) ? clickable : null);
				if (val2 == null)
				{
					BuildingGuildOld val3 = (BuildingGuildOld)(object)((clickable is BuildingGuildOld) ? clickable : null);
					if (val3 != null)
					{
						return GuildSetup.Invoke(val3);
					}
					return -1;
				}
				return ObjectShopSetup.Invoke(val2);
			}
			return ShopSetup.Invoke(val);
		}
	}

	internal Vector3 GetVisualTop(Dictionary<Sprite, Bounds> spriteMeshBounds)
	{
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_004e: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		SpriteRenderer spriteRenderer = SpriteRenderer;
		if ((Object)(object)spriteRenderer != (Object)null && ((Renderer)spriteRenderer).enabled && ((Component)spriteRenderer).gameObject.activeInHierarchy && (Object)(object)spriteRenderer.sprite != (Object)null)
		{
			if ((int)spriteRenderer.drawMode != 0)
			{
				return TopCenter(((Renderer)spriteRenderer).bounds, Position.z);
			}
			Sprite sprite = spriteRenderer.sprite;
			if (!spriteMeshBounds.TryGetValue(sprite, out var value))
			{
				Vector2[] vertices = sprite.vertices;
				value = (Bounds)((vertices.Length == 0) ? sprite.bounds : new Bounds(Vector2.op_Implicit(vertices[0]), Vector3.zero));
				for (int i = 1; i < vertices.Length; i++)
				{
					((Bounds)(ref value)).Encapsulate(Vector2.op_Implicit(vertices[i]));
				}
				spriteMeshBounds.Add(sprite, value);
			}
			Vector3 center = ((Bounds)(ref value)).center;
			if (spriteRenderer.flipX)
			{
				center.x = 0f - center.x;
			}
			if (spriteRenderer.flipY)
			{
				center.y = 0f - center.y;
			}
			Transform transform = ((Component)spriteRenderer).transform;
			Vector3 result = transform.TransformPoint(center);
			result.y += Mathf.Abs(transform.TransformVector(Vector3.right * ((Bounds)(ref value)).extents.x).y) + Mathf.Abs(transform.TransformVector(Vector3.up * ((Bounds)(ref value)).extents.y).y);
			result.z = Position.z;
			return result;
		}
		BoxCollider2D val = TargetCollider.Invoke(interaction);
		if (!((Object)(object)val != (Object)null) || !((Behaviour)val).isActiveAndEnabled)
		{
			return Position;
		}
		return TopCenter(((Collider2D)val).bounds, Position.z);
	}

	private static Vector3 TopCenter(Bounds bounds, float z)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y, z);
	}

	private MarkerTarget(ClickableSprite clickable, MarkerIcon kind, bool needsNativeMarker = false, UIArrowRoad arrow = null, Road road = null)
	{
		Clickable = clickable;
		BuildingTradingPost val = (BuildingTradingPost)(object)((clickable is BuildingTradingPost) ? clickable : null);
		interaction = (ClickableSprite)((val != null) ? ((object)WorldSites.TradingOverlay(val)) : ((object)clickable));
		InstanceId = ((Object)clickable).GetInstanceID();
		Kind = kind;
		NeedsNativeMarker = needsNativeMarker;
		roadArrow = arrow;
		this.road = road;
	}

	internal static MarkerTarget ForEvent(GameObject target)
	{
		ClickableSprite val = default(ClickableSprite);
		if (!target.TryGetComponent<ClickableSprite>(ref val))
		{
			return null;
		}
		MarkerTarget markerTarget = ForSite(val);
		if (markerTarget != null)
		{
			return markerTarget;
		}
		MarkerIcon? markerIcon = EncounterTargets.ForPickup(val);
		if (!markerIcon.HasValue)
		{
			return null;
		}
		return new MarkerTarget(val, markerIcon.Value, needsNativeMarker: true);
	}

	internal static MarkerTarget ForSite(ClickableSprite target)
	{
		if (target is BuildingShop || target is BuildingObjectShop || target is BuildingGuildOld)
		{
			return new MarkerTarget(target, MarkerIcon.Shop);
		}
		MarkerIcon? markerIcon = EncounterTargets.ForSite(target);
		if (!markerIcon.HasValue)
		{
			return null;
		}
		return new MarkerTarget(target, markerIcon.Value);
	}

	internal void AttachNativeMarker(UIMarker marker, Image image)
	{
		if (!((Object)(object)nativeMarker == (Object)(object)marker))
		{
			ReplaceNativeImage(replace: false);
			nativeMarker = marker;
			nativeImage = image;
			originalImageEnabled = ((Behaviour)image).enabled;
		}
	}

	internal static MarkerTarget ForRoad(UIArrowRoad arrow, RoadBuilder builder)
	{
		string text = RoadId.Invoke(arrow);
		Road val = (string.IsNullOrEmpty(text) ? null : builder.GetRoad(text));
		if (!((Object)(object)val == (Object)null))
		{
			return new MarkerTarget((ClickableSprite)(object)arrow, MarkerIcon.Road, needsNativeMarker: false, arrow, val);
		}
		return null;
	}

	internal void ReplaceNativeImage(bool replace)
	{
		if ((Object)(object)nativeImage != (Object)null && ((Behaviour)nativeImage).enabled != (originalImageEnabled && !replace))
		{
			((Behaviour)nativeImage).enabled = originalImageEnabled && !replace;
		}
	}

	internal MarkerState Read()
	{
		if (Expired)
		{
			return MarkerState.Hidden;
		}
		if (Kind == MarkerIcon.Road)
		{
			return ReadRoad();
		}
		if (!((Behaviour)Clickable).isActiveAndEnabled || (Object)(object)interaction == (Object)null || !((Behaviour)interaction).isActiveAndEnabled)
		{
			return MarkerState.Hidden;
		}
		bool num;
		if (Kind != MarkerIcon.Provoke)
		{
			if (!((Object)(object)nativeMarker == (Object)null) && Kind != MarkerIcon.Shop)
			{
				goto IL_0080;
			}
			num = !IsExposed();
		}
		else
		{
			num = !IsUncovered();
		}
		if (num)
		{
			return MarkerState.Hidden;
		}
		goto IL_0080;
		IL_0080:
		if (Kind == MarkerIcon.Shop && DaytimeManager.Instance.CurrentDay() <= SetupDay)
		{
			ClickableSprite clickable = Clickable;
			BuildingShop val = (BuildingShop)(object)((clickable is BuildingShop) ? clickable : null);
			SpriteRenderer val4;
			if (val == null)
			{
				BuildingObjectShop val2 = (BuildingObjectShop)(object)((clickable is BuildingObjectShop) ? clickable : null);
				if (val2 == null)
				{
					BuildingGuildOld val3 = (BuildingGuildOld)(object)((clickable is BuildingGuildOld) ? clickable : null);
					val4 = ((val3 == null) ? null : GuildCountdown.Invoke(val3));
				}
				else
				{
					val4 = ObjectShopCountdown.Invoke(val2);
				}
			}
			else
			{
				val4 = ShopCountdown.Invoke(val);
			}
			SpriteRenderer val5 = val4;
			if (!((Object)(object)val5 != (Object)null) || !((Renderer)val5).enabled || !((Component)val5).gameObject.activeInHierarchy || !((Object)(object)val5.sprite != (Object)null))
			{
				return MarkerState.Hidden;
			}
			return MarkerState.Setup;
		}
		BoxCollider2D val6 = TargetCollider.Invoke(interaction);
		if (!interaction.IsInteractable() || (Object)(object)val6 == (Object)null || !((Behaviour)val6).isActiveAndEnabled)
		{
			return MarkerState.Hidden;
		}
		switch (Kind)
		{
		case MarkerIcon.Treasure:
		case MarkerIcon.Hermit:
		case MarkerIcon.Reward:
			return MarkerState.Available;
		case MarkerIcon.Shop:
			if (!(Clickable is BuildingGuildOld) || Clickable is BuildingBlackMarket || UnitManager.Instance.GetCurrentHungryUnitsAmount() != 16)
			{
				return MarkerState.Available;
			}
			return MarkerState.Restricted;
		case MarkerIcon.Restore:
		case MarkerIcon.TradingPost:
		case MarkerIcon.Site:
			return WorldSites.Read(Clickable, interaction);
		default:
			return EncounterTargets.Read(Clickable);
		}
	}

	private bool IsExposed()
	{
		SpriteRenderer spriteRenderer = SpriteRenderer;
		if (IsUncovered() && (Object)(object)spriteRenderer != (Object)null && ((Renderer)spriteRenderer).enabled && ((Component)spriteRenderer).gameObject.activeInHierarchy)
		{
			return (Object)(object)spriteRenderer.sprite != (Object)null;
		}
		return false;
	}

	private bool IsUncovered()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		Tilemap fogTilemap = RaceManager.Instance.GetFogTilemap();
		if ((Object)(object)fogTilemap != (Object)null)
		{
			return !fogTilemap.HasTile(((GridLayout)fogTilemap).WorldToCell(Position));
		}
		return false;
	}

	private MarkerState ReadRoad()
	{
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)road == (Object)null || !((Component)road).gameObject.activeSelf || road.parts.Count == 0 || !((Component)roadArrow).gameObject.activeSelf)
		{
			return MarkerState.Hidden;
		}
		if (DaytimeManager.Instance.IsNight())
		{
			return MarkerState.Night;
		}
		if (DaytimeManager.Instance.CurrentDay() <= 1 && road.requiredGlory > 0)
		{
			return MarkerState.DayOne;
		}
		if (WorldManager.Instance.GetGlory() < road.requiredGlory)
		{
			return MarkerState.Glory;
		}
		if (RaceDataManager.Instance.GetKingdomLevel() < road.requiredKingdomLevel)
		{
			return MarkerState.Level;
		}
		if (RaceDataManager.Instance.GetStars() < road.requiredStars)
		{
			return MarkerState.Stars;
		}
		if (!ResourceManager.Instance.CanBeBuilt(road.GetCost()))
		{
			return MarkerState.Cost;
		}
		return MarkerState.Available;
	}

	internal (string Title, string Reason) GetTooltip(MarkerState state)
	{
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		string item;
		switch (Kind)
		{
		case MarkerIcon.Treasure:
			item = "Treasure chest";
			break;
		case MarkerIcon.Hermit:
			item = "Hermit";
			break;
		case MarkerIcon.Reward:
			item = "World reward";
			break;
		case MarkerIcon.Road:
			item = (road.city ? "City expansion" : (((Object)(object)road.pier != (Object)null) ? "Water access" : "Road expansion"));
			break;
		case MarkerIcon.Shop:
		{
			ClickableSprite clickable = Clickable;
			BuildingShop val = (BuildingShop)(object)((clickable is BuildingShop) ? clickable : null);
			string text;
			if (val == null)
			{
				BuildingObjectShop val2 = (BuildingObjectShop)(object)((clickable is BuildingObjectShop) ? clickable : null);
				if (val2 == null)
				{
					BuildingBlackMarket val3 = (BuildingBlackMarket)(object)((clickable is BuildingBlackMarket) ? clickable : null);
					if (val3 == null)
					{
						BuildingGuildOld val4 = (BuildingGuildOld)(object)((clickable is BuildingGuildOld) ? clickable : null);
						text = ((val4 == null) ? "Shop" : Localize(GuildTitle.Invoke(val4), "Guild"));
					}
					else
					{
						text = Localize(GuildTitle.Invoke((BuildingGuildOld)(object)val3), "Black Market");
					}
				}
				else
				{
					text = Localize(ObjectShopTitle.Invoke(val2), "Shop");
				}
			}
			else
			{
				text = Localize(ShopTitle.Invoke(val), "Shop");
			}
			item = text;
			break;
		}
		case MarkerIcon.Restore:
		case MarkerIcon.TradingPost:
		case MarkerIcon.Site:
			return WorldSites.Describe(Clickable, state);
		default:
			return EncounterTargets.Describe(Clickable, state);
		}
		string item2;
		switch (state)
		{
		case MarkerState.Setup:
			item2 = $"Opens on day {SetupDay + 1}";
			break;
		case MarkerState.DayOne:
			item2 = "Available from day 2";
			break;
		case MarkerState.Night:
			item2 = Localize(TooLate.Invoke(roadArrow), "Unavailable at night");
			break;
		case MarkerState.Glory:
			item2 = Localize(NeedGlory.Invoke(roadArrow), $"Requires {road.requiredGlory} glory");
			break;
		case MarkerState.Level:
			item2 = Localize(NeedLevel.Invoke(roadArrow), $"Requires kingdom level {road.requiredKingdomLevel}");
			break;
		case MarkerState.Stars:
			item2 = Localize(NeedStars.Invoke(roadArrow), $"Requires {road.requiredStars} stars");
			break;
		case MarkerState.Cost:
			item2 = EncounterTargets.FormatCost(road.GetCost(), blocked: true);
			break;
		case MarkerState.Restricted:
		{
			ClickableSprite clickable2 = Clickable;
			BuildingGuildOld val5 = (BuildingGuildOld)(object)((clickable2 is BuildingGuildOld) ? clickable2 : null);
			if (val5 != null)
			{
				item2 = Localize(GuildFull.Invoke(val5), "No room to recruit another unit");
				break;
			}
			goto default;
		}
		default:
			return (Title: item, Reason: null);
		}
		return (Title: item, Reason: item2);
	}

	private static string Localize(LocalizedString text, string fallback)
	{
		if (text != null && !((LocalizedReference)text).IsEmpty)
		{
			return text.GetLocalizedString();
		}
		return fallback;
	}
}
[BepInPlugin("gkj.scoutsmap", "Scout's Map", "0.4.2")]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(UIMarker), "Init", new Type[]
	{
		typeof(GameObject),
		typeof(Sprite)
	})]
	private static class NativeEventMarker
	{
		private static void Postfix(UIMarker __instance, GameObject o, Sprite icon, Image ___image)
		{
			if ((Object)(object)instance == (Object)null || (Object)(object)o == (Object)null || (Object)(object)icon != (Object)null || (Object)(object)___image == (Object)null)
			{
				return;
			}
			MarkerTarget markerTarget = MarkerTarget.ForEvent(o);
			if (markerTarget == null)
			{
				return;
			}
			if (instance.discovered.TryGetValue(markerTarget.InstanceId, out var value))
			{
				value.AttachNativeMarker(__instance, ___image);
				return;
			}
			markerTarget.AttachNativeMarker(__instance, ___image);
			instance.discovered.Add(markerTarget.InstanceId, markerTarget);
			if (markerTarget.Kind == MarkerIcon.Apple || markerTarget.Kind == MarkerIcon.Rare || markerTarget.Kind == MarkerIcon.Salvage)
			{
				instance.markers.Add(markerTarget);
			}
			else
			{
				instance.markers.Insert(0, markerTarget);
			}
		}
	}

	[HarmonyPatch(typeof(GameInputManager), "GameClick", new Type[] { typeof(CallbackContext) })]
	private static class MouseSpellClick
	{
		private static bool Prefix(CallbackContext context)
		{
			//IL_0057: 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)
			if (!((Object)(object)instance == (Object)null) && ((CallbackContext)(ref context)).performed)
			{
				InputControl control = ((CallbackContext)(ref context)).control;
				InputDevice obj = ((control != null) ? control.device : null);
				Mouse val = (Mouse)(object)((obj is Mouse) ? obj : null);
				if (val != null && (!((Object)(object)VirtualInputManager.Instance != (Object)null) || !VirtualInputManager.Instance.IsVirtualInput(context)))
				{
					return !instance.BadgeAt(((InputControl<Vector2>)(object)((Pointer)val).position).ReadValue());
				}
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(GameCamera), "Update")]
	private static class CameraDrag
	{
		private static bool Prefix(GameCamera __instance, ref Vector3 ___m_DragOrigin)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to i