Decompiled source of Sail a dex v1.3.1

Sail-a-dex\Sail-a-dex.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SailwindModdingHelper;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using cakeslice;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Sail-a-dex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sail-a-dex")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("165a01b3-48da-400d-a25f-d6d01b2b3120")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.3.1.0")]
namespace sailadex;

internal class PassageDude
{
	public class FerryTravelPatches
	{
		[HarmonyPostfix]
		public static void TeleportPlayerPatch()
		{
			if (Plugin.statsUIEnabled.Value)
			{
				StatsUI.instance.PlayerTeleported();
			}
		}
	}

	public static void PatchMod()
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		Type type2 = (from type in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly asm) => asm.GetTypes())
			where type.IsClass && type.Name == "FerryTravel"
			select type).Single();
		MethodInfo methodInfo = AccessTools.Method(type2, "TeleportPlayer", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(FerryTravelPatches), "TeleportPlayerPatch", (Type[])null, (Type[])null);
		Plugin.harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}
}
internal class RandomEncounters
{
	public class EncounterGeneratorPatches
	{
		[HarmonyPostfix]
		public static void FlotsamCountPatch()
		{
			StatsUI.instance.IncrementIntStat("FlotsamEncounters");
		}

		[HarmonyPostfix]
		public static void SeaLifeCountPatch()
		{
			if (isSeaLifeEnabled)
			{
				StatsUI.instance.IncrementIntStat("SeaLifeEncounters");
			}
		}
	}

	internal static BaseUnityPlugin pluginInstance;

	internal static bool isSeaLifeEnabled;

	public static void PatchMod()
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		BaseUnityPlugin privateField = Extensions.GetPrivateField<BaseUnityPlugin>((object)pluginInstance, "seaLifeModInstance");
		ConfigEntry<bool> privateField2 = Extensions.GetPrivateField<ConfigEntry<bool>>((object)pluginInstance, "controlSeaLifeMod");
		isSeaLifeEnabled = (Object)(object)privateField != (Object)null && privateField2.Value;
		Type type2 = (from type in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly asm) => asm.GetTypes())
			where type.IsClass && type.Name == "EncounterGenerator"
			select type).Single();
		MethodInfo methodInfo = AccessTools.Method(type2, "GenerateFlotsam", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(EncounterGeneratorPatches), "FlotsamCountPatch", (Type[])null, (Type[])null);
		Plugin.harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo3 = AccessTools.Method(type2, "GenerateWhale", (Type[])null, (Type[])null);
		MethodInfo methodInfo4 = AccessTools.Method(typeof(EncounterGeneratorPatches), "SeaLifeCountPatch", (Type[])null, (Type[])null);
		Plugin.harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}
}
internal class EventPatches
{
	[HarmonyPatch(typeof(FishingRodFish))]
	private class FishingRodFishPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("CollectFish")]
		public static void CollectFishPatch(FishingRodFish __instance, GameObject ___currentFish)
		{
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				FishCaughtUI.instance.RegisterCatch(___currentFish);
			}
		}
	}

	[HarmonyPatch(typeof(IslandMarketWarehouseArea))]
	private class IslandMarketWarehouseAreaPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnTriggerEnter")]
		public static void OnTriggerEnterPatch(IslandMarketWarehouseArea __instance, IslandMarket ___market, Collider other)
		{
			if (Plugin.portsVisitedUIEnabled.Value && ((Component)other).CompareTag("Player"))
			{
				PortsVisitedUI.instance.RegisterVisit(___market.GetPortName());
			}
			if (Plugin.statsUIEnabled.Value && ((Component)other).CompareTag("Player"))
			{
				StatsUI.instance.IncrementPortVisited(___market.GetPortName());
			}
		}
	}

	[HarmonyPatch(typeof(ShipItem))]
	private class ShipItemPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("EnterBoat")]
		public static void EnterBoatPatch()
		{
			if (Plugin.statsUIEnabled.Value && GameState.playing)
			{
				StatsUI.instance.RegisterCurrentMass();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ExitBoat")]
		public static void ExitBoatPatch()
		{
			if (Plugin.statsUIEnabled.Value && GameState.playing)
			{
				StatsUI.instance.RegisterCurrentMass();
			}
		}
	}

	[HarmonyPatch(typeof(PickupableBoatMooringRope))]
	private class PickupableBoatMooringRopePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnPickup")]
		public static void OnPickupPrePatch(Rigidbody ___boatRigidbody, out string __state)
		{
			__state = (from r in ((Component)___boatRigidbody).gameObject.GetComponent<BoatMooringRopes>().ropes
				where (Object)(object)Extensions.GetPrivateField<SpringJoint>((object)r, "mooredToSpring") != (Object)null
				select ((Object)((Component)Extensions.GetPrivateField<SpringJoint>((object)r, "mooredToSpring")).transform.parent).name).FirstOrDefault();
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnPickup")]
		public static void OnPickupPatch(Rigidbody ___boatRigidbody, string __state)
		{
			if (Plugin.statsUIEnabled.Value && !GameState.currentlyLoading && GameState.playing && !((Component)___boatRigidbody).gameObject.GetComponent<BoatMooringRopes>().AnyRopeMoored())
			{
				Plugin.logger.LogDebug((object)$"Unmoor from {__state} Day: {GameState.day} Time: {Sun.sun.globalTime}");
				StatsUI.instance.RegisterUnderway(__state);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("MoorTo")]
		public static void MoorToPatch(Rigidbody ___boatRigidbody)
		{
			if (!Plugin.statsUIEnabled.Value || GameState.currentlyLoading || !GameState.playing)
			{
				return;
			}
			if (!((Object)(object)((Component)___boatRigidbody).transform == (Object)(object)GameState.lastBoat))
			{
				Transform transform = ((Component)___boatRigidbody).transform;
				Transform currentBoat = GameState.currentBoat;
				if (!((Object)(object)transform == (Object)(object)((currentBoat != null) ? currentBoat.parent : null)))
				{
					return;
				}
			}
			if (((Component)___boatRigidbody).gameObject.GetComponent<BoatMooringRopes>().AnyRopeMoored())
			{
				string text = (from r in ((Component)___boatRigidbody).gameObject.GetComponent<BoatMooringRopes>().ropes
					where (Object)(object)Extensions.GetPrivateField<SpringJoint>((object)r, "mooredToSpring") != (Object)null
					select ((Object)((Component)Extensions.GetPrivateField<SpringJoint>((object)r, "mooredToSpring")).transform.parent).name).FirstOrDefault();
				Plugin.logger.LogDebug((object)$"Moored at: {text} Day: {GameState.day} Time: {Sun.sun.globalTime} ");
				StatsUI.instance.RegisterMoored(text);
				StatsUI.instance.UpdateMilesText();
			}
		}
	}

	[HarmonyPatch(typeof(ShipItemBottle))]
	private class ShipItemBottlePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Drink")]
		public static void DrinkPatch(float ___health)
		{
			if (Plugin.statsUIEnabled.Value && ___health > 0f)
			{
				StatsUI.instance.IncrementIntStat("DrinksTaken");
			}
		}
	}

	[HarmonyPatch(typeof(ShipItemFood))]
	private class ShipItemFoodPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("EatFood")]
		public static void EatFoodPatch()
		{
			if (Plugin.statsUIEnabled.Value && !(PlayerNeeds.instance.eatCooldown > 0f))
			{
				StatsUI.instance.IncrementIntStat("FoodsEaten");
			}
		}
	}

	[HarmonyPatch(typeof(ShipItemPipe))]
	private class ShipItemPipePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("StopSmoking")]
		public static void StopSmokingPatch(float ___currentInhaleDuration)
		{
			if (Plugin.statsUIEnabled.Value && ___currentInhaleDuration > 0f)
			{
				StatsUI.instance.IncrementIntStat("TimesSmoked");
			}
		}
	}

	[HarmonyPatch(typeof(Sleep))]
	private class SleepPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("EnterBed")]
		public static void EnterBedPatch()
		{
			if (Plugin.statsUIEnabled.Value)
			{
				StatsUI.instance.IncrementIntStat("TimesSlept");
				if (Plugin.updateMilesSailed.Value == "sleep")
				{
					StatsUI.instance.UpdateMilesText();
				}
			}
		}
	}

	[HarmonyPatch(typeof(PlayerMissions))]
	private class PlayerMissionsPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("CompleteMission")]
		public static void CompleteMissionPatch()
		{
			if (Plugin.statsUIEnabled.Value)
			{
				StatsUI.instance.IncrementIntStat("MissionsCompleted");
			}
		}
	}

	[HarmonyPatch(typeof(Port))]
	private class PortPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePatch(bool ___teleportPlayer)
		{
			if (Plugin.statsUIEnabled.Value && ___teleportPlayer)
			{
				StatsUI.instance.PlayerTeleported();
			}
		}
	}

	[HarmonyPatch(typeof(BoatMass))]
	private class BoatMassPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("FixedUpdate")]
		public static void FixedUpdatePatch()
		{
			if (Plugin.statsUIEnabled.Value && (Object)(object)GameState.currentBoat != (Object)null)
			{
				StatsUI.instance.TrackDistance();
			}
		}
	}

	[HarmonyPatch(typeof(WeatherStorms))]
	private class WeatherStormPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("GetNormalizedDistance")]
		public static void GetNormalizedDistancePatch(float __result)
		{
			if (Plugin.statsUIEnabled.Value && (Object)(object)GameState.currentBoat != (Object)null && !((Component)GameState.currentBoat.parent).gameObject.GetComponent<BoatMooringRopes>().AnyRopeMoored() && __result <= Extensions.GetPrivateField<float>((object)WeatherStorms.instance, "rainBorder"))
			{
				StatsUI.instance.IncrementStormsWeathered();
			}
			if (__result > Extensions.GetPrivateField<float>((object)WeatherStorms.instance, "cloudyBorder"))
			{
				StatsUI.instance.ClearLastStorm();
			}
		}
	}
}
public class FishCaughtUI : MonoBehaviour
{
	public static FishCaughtUI instance;

	public Dictionary<string, int> caughtFish;

	public TextMesh[] fishNameTMs;

	public TextMesh[] caughtCountTMs;

	public Dictionary<string, bool> fishBadges;

	public Dictionary<string, GameObject> fishBadgeGOs;

	private void Awake()
	{
		instance = this;
		caughtFish = new Dictionary<string, int>();
		fishBadges = new Dictionary<string, bool>();
		fishBadgeGOs = new Dictionary<string, GameObject>();
		string[] fishNames = Names.fishNames;
		foreach (string text in fishNames)
		{
			caughtFish.Add(text, 0);
			fishBadges.Add(text + "25", value: false);
			fishBadges.Add(text + "50", value: false);
			fishBadges.Add(text + "100", value: false);
		}
		string[] totalFishBadgeNames = Names.totalFishBadgeNames;
		foreach (string key in totalFishBadgeNames)
		{
			fishBadges.Add(key, value: false);
		}
	}

	public void RegisterCatch(GameObject fish)
	{
		string name = ((ShipItem)fish.GetComponent<ShipItemFood>()).name;
		if (!caughtFish.ContainsKey(name))
		{
			Plugin.logger.LogWarning((object)("Fish caught " + name + " is not in fish caught log"));
			return;
		}
		caughtFish[name]++;
		CheckBadges(name);
		Plugin.logger.LogDebug((object)("Caught: " + name));
	}

	public void UpdatePage()
	{
		UpdateTexts();
		UpdateBadges();
	}

	private void UpdateTexts()
	{
		int num = 0;
		int num2 = 0;
		foreach (KeyValuePair<string, int> item in caughtFish)
		{
			if (Plugin.fishNamesHidden.Value)
			{
				fishNameTMs[num].text = ((item.Value > 0) ? item.Key : "???");
			}
			else
			{
				fishNameTMs[num].text = item.Key;
			}
			caughtCountTMs[num].text = item.Value.ToString();
			num2 += item.Value;
			num++;
		}
		fishNameTMs[fishNameTMs.Length - 1].text = "Total";
		caughtCountTMs[caughtCountTMs.Length - 1].text = num2.ToString() ?? "";
	}

	public void CheckBadges(string fishName)
	{
		CheckIndividualFishBadges(fishName);
		CheckAllFishBadges();
	}

	public void CheckIndividualFishBadges(string fishName)
	{
		int[] array = new int[3] { 25, 50, 100 };
		int[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			int num = array2[i];
			if (!fishBadges[fishName + num] && caughtFish[fishName] >= num)
			{
				if (Plugin.notificationsEnabled.Value)
				{
					NotificationUiQueue.instance.QueueNotification($"Caught {num} {fishName}");
				}
				fishBadges[fishName + num] = true;
			}
		}
	}

	public void CheckAllFishBadges()
	{
		int num = caughtFish.Values.Sum();
		int[] array = new int[3] { 50, 250, 500 };
		for (int i = 0; i < array.Length; i++)
		{
			if (!fishBadges[Names.totalFishBadgeNames[i]] && num >= array[i])
			{
				if (Plugin.notificationsEnabled.Value)
				{
					NotificationUiQueue.instance.QueueNotification($"Caught {array[i]} fish");
				}
				fishBadges[Names.totalFishBadgeNames[i]] = true;
			}
		}
		if (!fishBadges[Names.totalFishBadgeNames[3]] && !caughtFish.Values.Where((int v) => v.Equals(0)).Any())
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Caught all fish");
			}
			fishBadges[Names.totalFishBadgeNames[3]] = true;
		}
	}

	private void UpdateBadges()
	{
		foreach (KeyValuePair<string, bool> fishBadge in fishBadges)
		{
			fishBadgeGOs[fishBadge.Key].SetActive(fishBadge.Value);
		}
	}
}
internal class LogUIPatches
{
	[HarmonyPatch(typeof(MissionListUI))]
	private class MissionListUIPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("HideUI")]
		public static void HideUIPatches(MissionListUI __instance)
		{
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				fishCaughtUI.SetActive(false);
			}
			if (Plugin.portsVisitedUIEnabled.Value)
			{
				portsVisitedUI.SetActive(false);
			}
			if (Plugin.statsUIEnabled.Value)
			{
				statsUI.SetActive(false);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SwitchMode")]
		public static void SwitchModePatches(MissionListMode mode)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected I4, but got Unknown
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				fishCaughtUI.SetActive(false);
			}
			if (Plugin.portsVisitedUIEnabled.Value)
			{
				portsVisitedUI.SetActive(false);
			}
			if (Plugin.statsUIEnabled.Value)
			{
				statsUI.SetActive(false);
			}
			switch (mode - 5)
			{
			case 0:
				fishCaughtUI.SetActive(true);
				FishCaughtUI.instance.UpdatePage();
				break;
			case 1:
				portsVisitedUI.SetActive(true);
				PortsVisitedUI.instance.UpdatePage();
				break;
			case 2:
				statsUI.SetActive(true);
				StatsUI.instance.UpdatePage();
				break;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		public static void StartPatch(MissionListUI __instance, GameObject ___modeButtons, GameObject ___reputationUI)
		{
			AssetsLoader.Start();
			bookmarkPos = new Stack<float>();
			bookmarkPos.Push(-0.515f);
			bookmarkPos.Push(-0.387f);
			bookmarkPos.Push(-0.26f);
			if (Plugin.notificationSoundVolume.Value > 0f)
			{
				AssetsLoader.LoadAudio();
			}
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				AssetsLoader.LoadFishBadges();
				MakeFishCaughtUI(___modeButtons, ___reputationUI);
			}
			if (Plugin.portsVisitedUIEnabled.Value)
			{
				AssetsLoader.LoadPortBadges();
				MakePortsVisitedUI(___modeButtons, ___reputationUI);
			}
			if (Plugin.statsUIEnabled.Value)
			{
				MakeStatsUI(___modeButtons, ___reputationUI);
			}
		}

		private static void MakeFishCaughtUI(GameObject modeButtons, GameObject repUI)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0142: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: 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_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_061c: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)modeButtons.transform.GetChild(9)).gameObject;
			GameObject val = Object.Instantiate<GameObject>(gameObject);
			val.transform.parent = modeButtons.transform;
			Transform transform = val.transform;
			float num = bookmarkPos.Pop();
			Vector3 localPosition = gameObject.transform.localPosition;
			float num2 = ((Vector3)(ref localPosition))[1];
			localPosition = gameObject.transform.localPosition;
			transform.localPosition = new Vector3(num, num2, ((Vector3)(ref localPosition))[2]);
			val.transform.localRotation = gameObject.transform.localRotation;
			val.transform.localScale = gameObject.transform.localScale;
			((Object)val).name = "bookmark fish caught";
			((Component)val.transform.GetChild(0)).gameObject.GetComponent<TextMesh>().text = "fish caught";
			GPButtonLogMode component = val.GetComponent<GPButtonLogMode>();
			Traverse.Create((object)component).Field("mode").SetValue((object)(MissionListMode)5);
			Object.Destroy((Object)(object)val.GetComponent<Outline>());
			fishCaughtUI = Object.Instantiate<GameObject>(repUI);
			Object.Destroy((Object)(object)fishCaughtUI.GetComponent<ReputationUI>());
			fishCaughtUI.transform.parent = repUI.transform.parent;
			fishCaughtUI.transform.localPosition = repUI.transform.localPosition;
			fishCaughtUI.transform.localRotation = repUI.transform.localRotation;
			fishCaughtUI.transform.localScale = repUI.transform.localScale;
			((Object)fishCaughtUI).name = "fish caught ui";
			Object.Destroy((Object)(object)((Component)fishCaughtUI.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)fishCaughtUI.transform.GetChild(1)).gameObject);
			fishCaughtUI.AddComponent<FishCaughtUI>();
			GameObject gameObject2 = ((Component)fishCaughtUI.transform.GetChild(0)).gameObject;
			gameObject2.GetComponent<TextMesh>().font = ((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().font;
			((Renderer)gameObject2.GetComponent<MeshRenderer>()).material = ((Renderer)((Component)gameObject2.transform.GetChild(1)).GetComponent<MeshRenderer>()).material;
			((Object)((Component)gameObject2.transform.GetChild(1)).gameObject).name = "caught count";
			Transform child = gameObject2.transform.GetChild(1);
			localPosition = gameObject2.transform.GetChild(1).localPosition;
			child.localPosition = new Vector3(55f, 0f, ((Vector3)(ref localPosition))[2]);
			((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().fontSize = 50;
			TextMesh[] array = (TextMesh[])(object)new TextMesh[Names.fishNames.Length + 1];
			TextMesh[] array2 = (TextMesh[])(object)new TextMesh[Names.fishNames.Length + 1];
			for (int i = 0; i < Names.fishNames.Length; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(gameObject2);
				Object.Destroy((Object)(object)((Component)val2.transform.GetChild(4)).gameObject);
				Object.Destroy((Object)(object)((Component)val2.transform.GetChild(3)).gameObject);
				Object.Destroy((Object)(object)((Component)val2.transform.GetChild(2)).gameObject);
				Object.Destroy((Object)(object)((Component)val2.transform.GetChild(0)).gameObject);
				val2.GetComponent<TextMesh>().fontSize = 50;
				((Object)val2).name = Names.fishNames[i];
				val2.transform.parent = gameObject2.transform.parent;
				Transform transform2 = val2.transform;
				float num3 = 0.24f - 0.0375f * (float)i;
				localPosition = gameObject2.transform.localPosition;
				transform2.localPosition = new Vector3(0.8f, num3, ((Vector3)(ref localPosition))[2]);
				val2.transform.localRotation = gameObject2.transform.localRotation;
				val2.transform.localScale = gameObject2.transform.localScale;
				array2[i] = val2.GetComponent<TextMesh>();
				array[i] = ((Component)val2.transform.GetChild(1)).GetComponent<TextMesh>();
				string[] array3 = new string[3] { "25", "50", "100" };
				for (int j = 0; j < array3.Length; j++)
				{
					string text = ((Object)val2).name + array3[j];
					GameObject value = CreateBadgeObject(text, val2.transform, new Vector3(12f, 12f, 1f), new Vector3(75f + (float)j * 13f, 0f, 0f));
					FishCaughtUI.instance.fishBadgeGOs.Add(text, value);
				}
			}
			GameObject val3 = Object.Instantiate<GameObject>(gameObject2);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(4)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(3)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(0)).gameObject);
			((Object)val3).name = "totalCaught";
			val3.transform.parent = gameObject2.transform.parent;
			Transform transform3 = val3.transform;
			localPosition = gameObject2.transform.localPosition;
			transform3.localPosition = new Vector3(0.8f, -0.21f, ((Vector3)(ref localPosition))[2]);
			val3.transform.localRotation = gameObject2.transform.localRotation;
			val3.transform.localScale = gameObject2.transform.localScale;
			array2[Names.fishNames.Length] = val3.GetComponent<TextMesh>();
			array[Names.fishNames.Length] = ((Component)val3.transform.GetChild(1)).GetComponent<TextMesh>();
			string[] array4 = new string[4] { "caught50", "caught250", "caught500", "caughtAll" };
			for (int k = 0; k < array4.Length; k++)
			{
				string text2 = array4[k];
				GameObject value2 = CreateBadgeObject(text2, val3.transform, new Vector3(15f, 15f, 1f), new Vector3(15f + (float)k * 20f, -13f, 0f));
				FishCaughtUI.instance.fishBadgeGOs.Add(text2, value2);
			}
			Object.Destroy((Object)(object)gameObject2);
			FishCaughtUI.instance.fishNameTMs = array2;
			FishCaughtUI.instance.caughtCountTMs = array;
			Plugin.logger.LogInfo((object)"Loaded fish caught UI");
		}

		private static void MakePortsVisitedUI(GameObject modeButtons, GameObject repUI)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0568: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)modeButtons.transform.GetChild(9)).gameObject;
			GameObject val = Object.Instantiate<GameObject>(gameObject);
			val.transform.parent = modeButtons.transform;
			Transform transform = val.transform;
			float num = bookmarkPos.Pop();
			Vector3 localPosition = gameObject.transform.localPosition;
			transform.localPosition = new Vector3(num, 0.0028f, ((Vector3)(ref localPosition))[2]);
			val.transform.localRotation = gameObject.transform.localRotation;
			val.transform.localScale = gameObject.transform.localScale;
			((Object)val).name = "bookmark ports visited";
			((Component)val.transform.GetChild(0)).gameObject.GetComponent<TextMesh>().text = "ports visited";
			GPButtonLogMode component = val.GetComponent<GPButtonLogMode>();
			Traverse.Create((object)component).Field("mode").SetValue((object)(MissionListMode)6);
			Object.Destroy((Object)(object)val.GetComponent<Outline>());
			portsVisitedUI = Object.Instantiate<GameObject>(repUI);
			Object.Destroy((Object)(object)portsVisitedUI.GetComponent<ReputationUI>());
			portsVisitedUI.transform.parent = repUI.transform.parent;
			portsVisitedUI.transform.localPosition = repUI.transform.localPosition;
			portsVisitedUI.transform.localRotation = repUI.transform.localRotation;
			portsVisitedUI.transform.localScale = repUI.transform.localScale;
			((Object)portsVisitedUI).name = "ports visited ui";
			portsVisitedUI.AddComponent<PortsVisitedUI>();
			Transform child = portsVisitedUI.transform.GetChild(0);
			localPosition = portsVisitedUI.transform.GetChild(0).localPosition;
			child.localPosition = new Vector3(0.75f, 0.22f, ((Vector3)(ref localPosition))[2]);
			Transform child2 = portsVisitedUI.transform.GetChild(1);
			localPosition = portsVisitedUI.transform.GetChild(1).localPosition;
			child2.localPosition = new Vector3(0.75f, 0.01f, ((Vector3)(ref localPosition))[2]);
			Transform child3 = portsVisitedUI.transform.GetChild(2);
			localPosition = portsVisitedUI.transform.GetChild(2).localPosition;
			child3.localPosition = new Vector3(0.02f, 0.22f, ((Vector3)(ref localPosition))[2]);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)portsVisitedUI.transform.GetChild(1)).gameObject);
			val2.transform.parent = portsVisitedUI.transform;
			Transform transform2 = val2.transform;
			localPosition = portsVisitedUI.transform.GetChild(1).localPosition;
			transform2.localPosition = new Vector3(0.02f, 0.01f, ((Vector3)(ref localPosition))[2]);
			val2.transform.localRotation = portsVisitedUI.transform.GetChild(1).localRotation;
			val2.transform.localScale = portsVisitedUI.transform.GetChild(1).localScale;
			((Object)val2).name = "lagoon";
			val2.GetComponent<TextMesh>().text = "Fire Fish Lagoon";
			TextMesh[] array = (TextMesh[])(object)new TextMesh[Names.portNames.Length];
			TextMesh[] array2 = (TextMesh[])(object)new TextMesh[Names.portNames.Length];
			int num2 = 0;
			int[] array3 = new int[4] { 7, 6, 7, 4 };
			for (int i = 0; i < 4; i++)
			{
				Transform child4 = portsVisitedUI.transform.GetChild(i);
				Object.Destroy((Object)(object)((Component)child4.GetChild(1)).gameObject);
				Object.Destroy((Object)(object)((Component)child4.GetChild(2)).gameObject);
				Object.Destroy((Object)(object)((Component)child4.GetChild(4)).gameObject);
				GameObject gameObject2 = ((Component)child4.GetChild(0)).gameObject;
				GameObject gameObject3 = ((Component)child4.GetChild(3)).gameObject;
				((Object)gameObject2).name = "port1";
				gameObject2.transform.localPosition = new Vector3(5f, -8f, -0.1f);
				((Object)gameObject3).name = "visited port1";
				gameObject3.transform.localPosition = new Vector3(70f, -9f, 0f);
				array[num2] = gameObject2.GetComponent<TextMesh>();
				array2[num2] = gameObject3.GetComponent<TextMesh>();
				num2++;
				for (int j = 1; j < array3[i]; j++)
				{
					GameObject val3 = Object.Instantiate<GameObject>(gameObject2);
					val3.transform.parent = gameObject2.transform.parent;
					Transform transform3 = val3.transform;
					localPosition = gameObject2.transform.localPosition;
					float num3 = ((Vector3)(ref localPosition))[0];
					localPosition = gameObject2.transform.localPosition;
					float num4 = ((Vector3)(ref localPosition))[1] - 7.5f * (float)j;
					localPosition = gameObject2.transform.localPosition;
					transform3.localPosition = new Vector3(num3, num4, ((Vector3)(ref localPosition))[2]);
					val3.transform.localRotation = gameObject2.transform.localRotation;
					val3.transform.localScale = gameObject2.transform.localScale;
					((Object)val3).name = "port" + (j + 1);
					GameObject val4 = Object.Instantiate<GameObject>(gameObject3);
					val4.transform.parent = gameObject3.transform.parent;
					Transform transform4 = val4.transform;
					localPosition = gameObject3.transform.localPosition;
					float num5 = ((Vector3)(ref localPosition))[0];
					localPosition = gameObject3.transform.localPosition;
					float num6 = ((Vector3)(ref localPosition))[1] - 7.5f * (float)j;
					localPosition = gameObject3.transform.localPosition;
					transform4.localPosition = new Vector3(num5, num6, ((Vector3)(ref localPosition))[2]);
					val4.transform.localRotation = gameObject3.transform.localRotation;
					val4.transform.localScale = gameObject3.transform.localScale;
					((Object)val4).name = "visited port" + (j + 1);
					array[num2] = val3.GetComponent<TextMesh>();
					array2[num2] = val4.GetComponent<TextMesh>();
					num2++;
				}
				string text = ((Object)child4).name + "Badge";
				GameObject value = CreateBadgeObject(text, child4, new Vector3(15f, 15f, 1f), new Vector3(-8f, -2f, 0f));
				PortsVisitedUI.instance.portBadgeGOs.Add(text, value);
			}
			string text2 = "allPortsBadge";
			GameObject val5 = CreateBadgeObject(text2, portsVisitedUI.transform, new Vector3(0.1f, 0.0675f, 1f), new Vector3(-0.15f, -0.2f, -0.007f));
			val5.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
			PortsVisitedUI.instance.portBadgeGOs.Add(text2, val5);
			PortsVisitedUI.instance.portNameTMs = array;
			PortsVisitedUI.instance.portVisitedTMs = array2;
			Plugin.logger.LogInfo((object)"Loaded ports visited UI");
		}

		private static void MakeStatsUI(GameObject modeButtons, GameObject repUI)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_013d: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)modeButtons.transform.GetChild(9)).gameObject;
			GameObject val = Object.Instantiate<GameObject>(gameObject);
			val.transform.parent = modeButtons.transform;
			val.transform.localPosition = new Vector3(bookmarkPos.Pop(), -0.0032f, -0.4566f);
			val.transform.localRotation = gameObject.transform.localRotation;
			val.transform.localScale = gameObject.transform.localScale;
			((Object)val).name = "bookmark stats";
			((Component)val.transform.GetChild(0)).gameObject.GetComponent<TextMesh>().text = "stats & transit";
			GPButtonLogMode component = val.GetComponent<GPButtonLogMode>();
			Traverse.Create((object)component).Field("mode").SetValue((object)(MissionListMode)7);
			Object.Destroy((Object)(object)val.GetComponent<Outline>());
			statsUI = Object.Instantiate<GameObject>(repUI);
			Object.Destroy((Object)(object)statsUI.GetComponent<ReputationUI>());
			statsUI.transform.parent = repUI.transform.parent;
			statsUI.transform.localPosition = repUI.transform.localPosition;
			statsUI.transform.localRotation = repUI.transform.localRotation;
			statsUI.transform.localScale = repUI.transform.localScale;
			((Object)statsUI).name = "stats ui";
			Object.Destroy((Object)(object)((Component)statsUI.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)statsUI.transform.GetChild(1)).gameObject);
			statsUI.AddComponent<StatsUI>();
			GameObject gameObject2 = ((Component)statsUI.transform.GetChild(0)).gameObject;
			gameObject2.GetComponent<TextMesh>().font = ((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().font;
			gameObject2.GetComponent<TextMesh>().fontSize = 45;
			((Renderer)gameObject2.GetComponent<MeshRenderer>()).material = ((Renderer)((Component)gameObject2.transform.GetChild(1)).GetComponent<MeshRenderer>()).material;
			((Object)((Component)gameObject2.transform.GetChild(0)).gameObject).name = "current value";
			gameObject2.transform.GetChild(0).localPosition = new Vector3(38f, 0f, 0f);
			((Component)gameObject2.transform.GetChild(0)).GetComponent<TextMesh>().font = ((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().font;
			((Component)gameObject2.transform.GetChild(0)).GetComponent<TextMesh>().fontSize = 45;
			((Component)gameObject2.transform.GetChild(0)).GetComponent<TextMesh>().anchor = (TextAnchor)3;
			((Renderer)((Component)gameObject2.transform.GetChild(0)).GetComponent<MeshRenderer>()).material = ((Renderer)((Component)gameObject2.transform.GetChild(1)).GetComponent<MeshRenderer>()).material;
			((Object)((Component)gameObject2.transform.GetChild(1)).gameObject).name = "record value";
			gameObject2.transform.GetChild(1).localPosition = new Vector3(80f, 0f, 0f);
			((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().fontSize = 45;
			((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().anchor = (TextAnchor)3;
			((Component)gameObject2.transform.GetChild(1)).GetComponent<TextMesh>().fontStyle = (FontStyle)0;
			Dictionary<string, TextMesh> statTMs = new Dictionary<string, TextMesh>();
			AddTrackedStat(gameObject2, "CargoMass", 0.205f, statTMs);
			AddTrackedStat(gameObject2, "UnderwayTime", 0.17f, statTMs);
			AddTrackedStat(gameObject2, "MilesSailed", 0.07f, statTMs, ltime: true);
			int num = 0;
			string[] intStatNames = Names.intStatNames;
			foreach (string text in intStatNames)
			{
				if (!(text == "UnderwayDay") && (!(text == "FlotsamEncounters") || !((Object)(object)RandomEncounters.pluginInstance == (Object)null)) && (!(text == "SeaLifeEncounters") || (!((Object)(object)RandomEncounters.pluginInstance == (Object)null) && RandomEncounters.isSeaLifeEnabled)))
				{
					AddTrackedStat(gameObject2, text, 0.035f - 0.035f * (float)num, statTMs, ltime: true);
					num++;
				}
			}
			int num2 = 0;
			string[] transitNames = Names.transitNames;
			foreach (string name in transitNames)
			{
				AddTrackedStat(gameObject2, name, 0.205f - 0.035f * (float)num2, statTMs, ltime: false, transit: true);
				num2++;
			}
			StatsUI.instance.statTMs = statTMs;
			((Object)gameObject2).name = "stats header";
			gameObject2.GetComponent<TextMesh>().text = "Stat                        Current                     Record";
			gameObject2.transform.localPosition = new Vector3(0.82f, 0.24f, -0.007f);
			gameObject2.GetComponent<TextMesh>().fontSize = 50;
			gameObject2.GetComponent<TextMesh>().fontStyle = (FontStyle)1;
			Object.Destroy((Object)(object)((Component)gameObject2.transform.GetChild(4)).gameObject);
			Object.Destroy((Object)(object)((Component)gameObject2.transform.GetChild(3)).gameObject);
			Object.Destroy((Object)(object)((Component)gameObject2.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)gameObject2.transform.GetChild(1)).gameObject);
			Object.Destroy((Object)(object)((Component)gameObject2.transform.GetChild(0)).gameObject);
			GameObject val2 = Object.Instantiate<GameObject>(gameObject2, gameObject2.transform.parent);
			((Object)val2).name = "lifetime stats header";
			val2.GetComponent<TextMesh>().text = "Lifetime Stats";
			val2.transform.localPosition = new Vector3(0.82f, 0.105f, -0.007f);
			Object.Destroy((Object)(object)((Component)val2.transform.GetChild(4)).gameObject);
			Object.Destroy((Object)(object)((Component)val2.transform.GetChild(3)).gameObject);
			Object.Destroy((Object)(object)((Component)val2.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)val2.transform.GetChild(1)).gameObject);
			Object.Destroy((Object)(object)((Component)val2.transform.GetChild(0)).gameObject);
			GameObject val3 = Object.Instantiate<GameObject>(gameObject2, gameObject2.transform.parent);
			((Object)val3).name = "transit times header";
			val3.GetComponent<TextMesh>().text = "Transit Times         Last                            Record";
			val3.transform.localPosition = new Vector3(0.12f, 0.24f, -0.007f);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(4)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(3)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(2)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(1)).gameObject);
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(0)).gameObject);
			Plugin.logger.LogInfo((object)"Loaded stats & transit UI");
		}

		private static void AddTrackedStat(GameObject templateGO, string name, float yPos, Dictionary<string, TextMesh> statTMs, bool ltime = false, bool transit = false)
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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)
			float num = (transit ? 0.12f : 0.82f);
			string text = (transit ? "last" : "current");
			GameObject val = Object.Instantiate<GameObject>(templateGO);
			Object.Destroy((Object)(object)((Component)val.transform.GetChild(4)).gameObject);
			Object.Destroy((Object)(object)((Component)val.transform.GetChild(3)).gameObject);
			Object.Destroy((Object)(object)((Component)val.transform.GetChild(2)).gameObject);
			if (ltime)
			{
				Object.Destroy((Object)(object)((Component)val.transform.GetChild(1)).gameObject);
				val.transform.GetChild(0).localPosition = new Vector3(40f, 0f, 0f);
			}
			((Object)val).name = name;
			val.transform.parent = templateGO.transform.parent;
			Transform transform = val.transform;
			Vector3 localPosition = templateGO.transform.localPosition;
			transform.localPosition = new Vector3(num, yPos, ((Vector3)(ref localPosition))[2]);
			val.transform.localRotation = templateGO.transform.localRotation;
			val.transform.localScale = templateGO.transform.localScale;
			statTMs[name] = val.GetComponent<TextMesh>();
			statTMs[text + name] = ((Component)val.transform.GetChild(0)).GetComponent<TextMesh>();
			if (!ltime)
			{
				statTMs["record" + name] = ((Component)val.transform.GetChild(1)).GetComponent<TextMesh>();
			}
		}

		private static GameObject CreateBadgeObject(string name, Transform parent, Vector3 scale, Vector3 position)
		{
			//IL_003d: 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)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
			val.layer = 5;
			Object.Destroy((Object)(object)val.GetComponent<MeshCollider>());
			((Renderer)val.GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0;
			val.transform.SetParent(parent, false);
			val.transform.localScale = scale;
			val.transform.localPosition = position;
			((Object)val).name = name;
			((Renderer)val.GetComponent<MeshRenderer>()).material = AssetsLoader.materials[name];
			return val;
		}
	}

	[HarmonyPatch(typeof(NotificationUi))]
	private class NotificationUiPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPatch(NotificationUi ___instance)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				((Component)___instance).gameObject.AddComponent<NotificationUiQueue>();
			}
		}
	}

	[Serializable]
	public class RaddudeSaveContainer
	{
		public Dictionary<string, int> caughtFish;

		public Dictionary<string, bool> visitedPorts;

		public Dictionary<string, bool> fishBadges;

		public Dictionary<string, bool> portBadges;

		public Dictionary<string, float> floatStats;

		public Dictionary<string, int> intStats;

		public Dictionary<string, bool[]> boolArrayStats;
	}

	private static GameObject fishCaughtUI;

	private static GameObject portsVisitedUI;

	private static GameObject statsUI;

	private const MissionListMode fishCaught = 5;

	private const MissionListMode portsVisited = 6;

	private const MissionListMode stats = 7;

	private static Stack<float> bookmarkPos;
}
internal class AssetsLoader
{
	public static Dictionary<string, Material> materials;

	public static Dictionary<string, Texture2D> textures;

	public static AudioClip notificationSound;

	public static void Start()
	{
		materials = new Dictionary<string, Material>();
		textures = new Dictionary<string, Texture2D>();
	}

	public static void LoadFishBadges()
	{
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location), "assets", "badges", "fish");
		int[] array = new int[3] { 25, 50, 100 };
		string[] fishNames = Names.fishNames;
		foreach (string text in fishNames)
		{
			for (int j = 0; j < 3; j++)
			{
				string text2 = text + array[j];
				Texture2D val = LoadTexture(Path.Combine(path, text2 + ".png"));
				textures.Add(text2, val);
				materials.Add(text2, CreateMaterial(val));
			}
		}
		string[] totalFishBadgeNames = Names.totalFishBadgeNames;
		foreach (string text3 in totalFishBadgeNames)
		{
			string text2 = text3;
			Texture2D val = LoadTexture(Path.Combine(path, text2 + ".png"));
			textures.Add(text2, val);
			materials.Add(text2, CreateMaterial(val));
		}
		Plugin.logger.LogInfo((object)"Fishing badges loaded.");
	}

	public static void LoadPortBadges()
	{
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location), "assets", "badges", "ports");
		string[] portBadgeNames = Names.portBadgeNames;
		foreach (string text in portBadgeNames)
		{
			Texture2D val = LoadTexture(Path.Combine(path, text + ".png"));
			textures.Add(text, val);
			materials.Add(text, CreateMaterial(val));
		}
		Plugin.logger.LogInfo((object)"Port badges loaded.");
	}

	private static Texture2D LoadTexture(string path)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		byte[] array = (File.Exists(path) ? File.ReadAllBytes(path) : null);
		Texture2D val = new Texture2D(1, 1);
		if (array == null)
		{
			Plugin.logger.LogError((object)("Failed to load " + path));
			return val;
		}
		ImageConversion.LoadImage(val, array);
		return val;
	}

	private static Material CreateMaterial(Texture2D tex)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		Material val = new Material(Shader.Find("Standard"))
		{
			renderQueue = 2001,
			mainTexture = (Texture)(object)tex
		};
		val.EnableKeyword("_ALPHATEST_ON");
		val.SetShaderPassEnabled("ShadowCaster", false);
		return val;
	}

	public static void GetAudioClip(string fileName, List<AudioClip> audioClips)
	{
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location), "assets", "sounds", fileName + ".wav");
		UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + text, (AudioType)20);
		audioClip.SendWebRequest();
		while (!audioClip.isDone)
		{
		}
		if (audioClip.isNetworkError)
		{
			Debug.Log((object)audioClip.error);
			return;
		}
		AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
		((Object)content).name = fileName;
		audioClips.Add(content);
	}

	public static void LoadAudio()
	{
		List<AudioClip> list = new List<AudioClip>();
		GetAudioClip("twoBells", list);
		Debug.Log((object)$"AudioClips length {list.Count}");
		notificationSound = list[0];
	}
}
internal static class Names
{
	public static string[] fishNames = new string[12]
	{
		"templefish", "sunspot fish", "tuna", "shimmertail", "salmon", "eel", "blackfin hunter", "trout", "north fish", "swamp snapper",
		"blue bubbler", "fire fish"
	};

	public static string[] totalFishBadgeNames = new string[4] { "caught50", "caught250", "caught500", "caughtAll" };

	public static string[] alankhPorts = new string[7] { "Gold Rock City", "Al'Nilem", "Neverdin", "Albacore Town", "Alchemist's Island", "Al'Ankh Academy", "Oasis" };

	public static string[] emeraldPorts = new string[6] { "Dragon Cliffs", "Sanctuary", "Crab Beach", "New Port", "Sage Hills", "Serpent Isle" };

	public static string[] mediPorts = new string[7] { "Fort Aestrin", "Sunspire", "Mount Malefic", "Siren Song", "Eastwind", "Happy Bay", "Chronos" };

	public static string[] lagoonPorts = new string[4] { "Kicia Bay", "Fire Fish Town", "On'na", "Sen'na" };

	public static string[] portNames = new string[24]
	{
		"Gold Rock City", "Al'Nilem", "Neverdin", "Albacore Town", "Alchemist's Island", "Al'Ankh Academy", "Oasis", "Dragon Cliffs", "Sanctuary", "Crab Beach",
		"New Port", "Sage Hills", "Serpent Isle", "Fort Aestrin", "Sunspire", "Mount Malefic", "Siren Song", "Eastwind", "Happy Bay", "Chronos",
		"Kicia Bay", "Fire Fish Town", "On'na", "Sen'na"
	};

	public static string[] capitals = new string[4] { "grc", "dc", "fa", "kb" };

	public static string[] portBadgeNames = new string[5] { "alankhBadge", "emeraldBadge", "mediBadge", "lagoonBadge", "allPortsBadge" };

	public static string[] floatStatNames = new string[3] { "CargoMass", "UnderwayTime", "MilesSailed" };

	public static string[] intStatNames = new string[10] { "UnderwayDay", "PortsVisited", "MissionsCompleted", "DrinksTaken", "FoodsEaten", "TimesSmoked", "TimesSlept", "StormsWeathered", "FlotsamEncounters", "SeaLifeEncounters" };

	public static string[] transitNames = new string[12]
	{
		"GrcDc", "GrcFa", "GrcKb", "DcGrc", "DcFa", "DcKb", "FaGrc", "FaDc", "FaKb", "KbGrc",
		"KbDc", "KbFa"
	};
}
public class NotificationUiQueue : MonoBehaviour
{
	public static NotificationUiQueue instance;

	private float timer;

	private Queue<string> queue;

	private AudioSource audioSource;

	public void Start()
	{
		instance = this;
		queue = new Queue<string>();
		timer = 0f;
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		audioSource.volume = Plugin.notificationSoundVolume.Value;
		audioSource.spatialBlend = 1f;
		audioSource.minDistance = 10f;
		audioSource.maxDistance = 20f;
	}

	private void Update()
	{
		if (timer > 0f)
		{
			timer -= Time.deltaTime;
			return;
		}
		timer = 0f;
		if (queue.Count > 0)
		{
			NotificationUi.instance.ShowNotification(queue.Dequeue());
			if (Plugin.notificationSoundVolume.Value > 0f)
			{
				audioSource.PlayOneShot(AssetsLoader.notificationSound);
			}
			timer = 3f;
		}
	}

	public void QueueNotification(string message)
	{
		queue.Enqueue(message);
	}
}
[BepInPlugin("com.raddude82.sailadex", "Sail-A-Dex", "1.3.1")]
[BepInDependency("com.app24.sailwindmoddinghelper", "2.1.1")]
[BepInDependency("com.raddude82.modsavebackups", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string PLUGIN_GUID = "com.raddude82.sailadex";

	public const string PLUGIN_NAME = "Sail-A-Dex";

	public const string PLUGIN_VERSION = "1.3.1";

	public const string SMH_GUID = "com.app24.sailwindmoddinghelper";

	public const string SMH_VERSION = "2.1.1";

	public const string MODSAVEBACKUPS_GUID = "com.raddude82.modsavebackups";

	public const string MODSAVEBACKUPS_VERSION = "1.0.2";

	public const string PASSAGEDUDE_GUID = "pr0skynesis.passagedude";

	public const string RANDOMENCOUNTERS_GUID = "com.raddude82.randomencounters";

	internal static ConfigEntry<bool> fishNamesHidden;

	internal static ConfigEntry<bool> portNamesHidden;

	internal static ConfigEntry<bool> fishCaughtUIEnabled;

	internal static ConfigEntry<bool> portsVisitedUIEnabled;

	internal static ConfigEntry<bool> statsUIEnabled;

	internal static ConfigEntry<bool> notificationsEnabled;

	internal static ConfigEntry<float> notificationSoundVolume;

	internal static ConfigEntry<string> updateMilesSailed;

	internal static Plugin instance;

	internal static ManualLogSource logger;

	internal static Harmony harmony;

	private void Awake()
	{
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Expected O, but got Unknown
		fishNamesHidden = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Hide Fish Names Before Caught", true, "true = fish names will be hidden before being caught for the first time.");
		portNamesHidden = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Hide Port Names Before Visited", false, "true = port names will be hidden before visited for the first time.");
		fishCaughtUIEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enable Fish Caught UI", true, "true = UI for how many fish you caught will be enabled. Setting to false, continuing a game where previously enabled, and then saving will erase all previous fish caught progress.");
		portsVisitedUIEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enable Ports Visited UI", true, "true = UI for which ports you have visited will be enabled. Setting to false, continuing a game where previously enabled, and then saving will erase all previous port visit progress.");
		statsUIEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enable Stats UI", true, "true = UI for various stats will be enabled. Setting to false, continuing a game where previously enabled, and then saving will erase all previously recorded stats.");
		notificationsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enable Notifications", true, "true = notifications on badge earned will be enabled.");
		notificationSoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Notification Volume", 0.2f, "Above 1f is loud and not recommended. Set to 0f to disable.");
		updateMilesSailed = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Miles Sailed Updates", "moored", new ConfigDescription("Miles sailed text will be updated once moored, going to sleeping or moored, or in real time.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "moored", "sleep", "realtime" }), Array.Empty<object>()));
		instance = this;
		logger = ((BaseUnityPlugin)this).Logger;
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.raddude82.sailadex");
		foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
		{
			BepInPlugin metadata = pluginInfo.Value.Metadata;
			if (metadata.GUID.Equals("pr0skynesis.passagedude"))
			{
				logger.LogInfo((object)"pr0skynesis.passagedude found");
				PassageDude.PatchMod();
			}
			if (metadata.GUID.Equals("com.raddude82.randomencounters"))
			{
				logger.LogInfo((object)"com.raddude82.randomencounters found");
				RandomEncounters.pluginInstance = pluginInfo.Value.Instance;
				RandomEncounters.PatchMod();
			}
		}
	}
}
public class PortsVisitedUI : MonoBehaviour
{
	public static PortsVisitedUI instance;

	public Dictionary<string, bool> visitedPorts;

	public TextMesh[] portNameTMs;

	public TextMesh[] portVisitedTMs;

	public Dictionary<string, bool> portBadges;

	public Dictionary<string, GameObject> portBadgeGOs;

	private void Awake()
	{
		instance = this;
		visitedPorts = new Dictionary<string, bool>();
		portBadges = new Dictionary<string, bool>();
		portBadgeGOs = new Dictionary<string, GameObject>();
		string[] portNames = Names.portNames;
		foreach (string key in portNames)
		{
			visitedPorts.Add(key, value: false);
		}
		string[] portBadgeNames = Names.portBadgeNames;
		foreach (string key2 in portBadgeNames)
		{
			portBadges.Add(key2, value: false);
		}
	}

	public void RegisterVisit(string portName)
	{
		if (visitedPorts.ContainsKey(portName) && !visitedPorts[portName])
		{
			visitedPorts[portName] = true;
			CheckBadges();
		}
		Plugin.logger.LogDebug((object)("Visited: " + portName));
	}

	public void UpdatePage()
	{
		UpdateTexts();
		UpdateBadges();
	}

	private void UpdateTexts()
	{
		int num = 0;
		foreach (KeyValuePair<string, bool> visitedPort in visitedPorts)
		{
			if (Plugin.portNamesHidden.Value)
			{
				portNameTMs[num].text = (visitedPort.Value ? visitedPort.Key : "???");
			}
			else
			{
				portNameTMs[num].text = visitedPort.Key;
			}
			portVisitedTMs[num].text = (visitedPort.Value ? "✓" : "✗");
			num++;
		}
	}

	public void CheckBadges()
	{
		bool flag = Names.alankhPorts.All((string p) => visitedPorts[p]);
		bool flag2 = Names.emeraldPorts.All((string p) => visitedPorts[p]);
		bool flag3 = Names.mediPorts.All((string p) => visitedPorts[p]);
		bool flag4 = Names.lagoonPorts.All((string p) => visitedPorts[p]);
		if (!portBadges["alankhBadge"] && flag)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Visited all Al'Ankh ports");
			}
			portBadges["alankhBadge"] = true;
		}
		if (!portBadges["emeraldBadge"] && flag2)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Visited all Emerald\nArchipelago ports");
			}
			portBadges["emeraldBadge"] = true;
		}
		if (!portBadges["mediBadge"] && flag3)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Visited all Aestrin ports");
			}
			portBadges["mediBadge"] = true;
		}
		if (!portBadges["lagoonBadge"] && flag4)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Visited all Fire\nFish Lagoon ports");
			}
			portBadges["lagoonBadge"] = true;
		}
		if (!portBadges["allPortsBadge"] && flag && flag2 && flag3 && flag4)
		{
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Visited all ports");
			}
			portBadges["allPortsBadge"] = true;
		}
	}

	public void UpdateBadges()
	{
		foreach (KeyValuePair<string, bool> portBadge in portBadges)
		{
			portBadgeGOs[portBadge.Key].SetActive(portBadge.Value);
		}
	}
}
internal class SaveLoadPatches
{
	[HarmonyPatch(typeof(SaveLoadManager))]
	private class SaveLoadManagerPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("SaveModData")]
		public static void DoSaveGamePatch()
		{
			SailadexSaveContainer sailadexSaveContainer = new SailadexSaveContainer();
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				sailadexSaveContainer.caughtFish = FishCaughtUI.instance.caughtFish.ToDictionary((KeyValuePair<string, int> entry) => entry.Key, (KeyValuePair<string, int> entry) => entry.Value);
				sailadexSaveContainer.fishBadges = FishCaughtUI.instance.fishBadges.ToDictionary((KeyValuePair<string, bool> entry) => entry.Key, (KeyValuePair<string, bool> entry) => entry.Value);
			}
			if (Plugin.portsVisitedUIEnabled.Value)
			{
				sailadexSaveContainer.visitedPorts = PortsVisitedUI.instance.visitedPorts.ToDictionary((KeyValuePair<string, bool> entry) => entry.Key, (KeyValuePair<string, bool> entry) => entry.Value);
				sailadexSaveContainer.portBadges = PortsVisitedUI.instance.portBadges.ToDictionary((KeyValuePair<string, bool> entry) => entry.Key, (KeyValuePair<string, bool> entry) => entry.Value);
			}
			if (Plugin.statsUIEnabled.Value)
			{
				sailadexSaveContainer.floatStats = StatsUI.instance.floatStats.ToDictionary((KeyValuePair<string, float> entry) => entry.Key, (KeyValuePair<string, float> entry) => entry.Value);
				sailadexSaveContainer.intStats = StatsUI.instance.intStats.ToDictionary((KeyValuePair<string, int> entry) => entry.Key, (KeyValuePair<string, int> entry) => entry.Value);
				sailadexSaveContainer.boolArrayStats = StatsUI.instance.boolArrayStats.ToDictionary((KeyValuePair<string, bool[]> entry) => entry.Key, (KeyValuePair<string, bool[]> entry) => entry.Value);
			}
			ModSave.Save(((BaseUnityPlugin)Plugin.instance).Info, (object)sailadexSaveContainer);
		}

		[HarmonyPatch("LoadModData")]
		[HarmonyPostfix]
		public static void LoadModDataPatch()
		{
			object obj = default(object);
			if (!ModSave.Load(((BaseUnityPlugin)Plugin.instance).Info, ref obj))
			{
				Plugin.logger.LogWarning((object)"Save file loading failed. If this is the first time loading this save with this mod, this is normal.");
				return;
			}
			SailadexSaveContainer sailadexSaveContainer;
			if (obj.GetType() == typeof(LogUIPatches.RaddudeSaveContainer))
			{
				Plugin.logger.LogDebug((object)"Converting save container");
				LogUIPatches.RaddudeSaveContainer raddudeSaveContainer = (LogUIPatches.RaddudeSaveContainer)obj;
				sailadexSaveContainer = new SailadexSaveContainer
				{
					caughtFish = raddudeSaveContainer.caughtFish,
					visitedPorts = raddudeSaveContainer.visitedPorts,
					fishBadges = raddudeSaveContainer.fishBadges,
					portBadges = raddudeSaveContainer.portBadges,
					floatStats = raddudeSaveContainer.floatStats,
					intStats = raddudeSaveContainer.intStats,
					boolArrayStats = raddudeSaveContainer.boolArrayStats
				};
			}
			else
			{
				sailadexSaveContainer = (SailadexSaveContainer)obj;
			}
			if (Plugin.fishCaughtUIEnabled.Value)
			{
				if (sailadexSaveContainer.caughtFish != null)
				{
					ConvertFishNames(sailadexSaveContainer.caughtFish, FishCaughtUI.instance.caughtFish);
				}
				if (sailadexSaveContainer.fishBadges != null)
				{
					LoadDictionary(sailadexSaveContainer.fishBadges, FishCaughtUI.instance.fishBadges);
				}
				string[] fishNames = Names.fishNames;
				foreach (string fishName in fishNames)
				{
					FishCaughtUI.instance.CheckIndividualFishBadges(fishName);
				}
				FishCaughtUI.instance.CheckAllFishBadges();
			}
			if (Plugin.portsVisitedUIEnabled.Value)
			{
				if (sailadexSaveContainer.visitedPorts != null)
				{
					LoadDictionary(sailadexSaveContainer.visitedPorts, PortsVisitedUI.instance.visitedPorts);
				}
				if (sailadexSaveContainer.portBadges != null)
				{
					LoadDictionary(sailadexSaveContainer.portBadges, PortsVisitedUI.instance.portBadges);
				}
				PortsVisitedUI.instance.CheckBadges();
			}
			if (!Plugin.statsUIEnabled.Value)
			{
				return;
			}
			if (sailadexSaveContainer.floatStats != null)
			{
				LoadDictionary(sailadexSaveContainer.floatStats, StatsUI.instance.floatStats);
			}
			if (sailadexSaveContainer.intStats != null)
			{
				LoadDictionary(sailadexSaveContainer.intStats, StatsUI.instance.intStats);
			}
			if (sailadexSaveContainer.boolArrayStats == null)
			{
				return;
			}
			foreach (KeyValuePair<string, bool[]> boolArrayStat in sailadexSaveContainer.boolArrayStats)
			{
				if (StatsUI.instance.boolArrayStats.ContainsKey(boolArrayStat.Key))
				{
					StatsUI.instance.boolArrayStats[boolArrayStat.Key] = (bool[])boolArrayStat.Value.Clone();
				}
				else
				{
					Plugin.logger.LogWarning((object)("LoadData: " + boolArrayStat.Key + " not found in game"));
				}
			}
		}

		public static void LoadDictionary<T>(Dictionary<string, T> saveDict, Dictionary<string, T> gameDict)
		{
			foreach (KeyValuePair<string, T> item in saveDict)
			{
				if (gameDict.ContainsKey(item.Key))
				{
					gameDict[item.Key] = item.Value;
				}
				else
				{
					Plugin.logger.LogWarning((object)("LoadData: " + item.Key + " not found in game"));
				}
			}
		}

		public static void ConvertFishNames(Dictionary<string, int> oldFishCount, Dictionary<string, int> newFishCount)
		{
			if (!oldFishCount.ContainsKey("31 templefish (A)"))
			{
				LoadDictionary(oldFishCount, newFishCount);
			}
			Plugin.logger.LogDebug((object)"Converting fishNames in fish caught counts");
			foreach (KeyValuePair<string, int> item in oldFishCount)
			{
				string text = item.Key;
				if (Regex.IsMatch(text, "^\\d"))
				{
					text = text.Substring(3, text.IndexOf("(") - 4);
				}
				newFishCount[text] = item.Value;
			}
		}
	}
}
[Serializable]
public class SailadexSaveContainer
{
	public Dictionary<string, int> caughtFish;

	public Dictionary<string, bool> visitedPorts;

	public Dictionary<string, bool> fishBadges;

	public Dictionary<string, bool> portBadges;

	public Dictionary<string, float> floatStats;

	public Dictionary<string, int> intStats;

	public Dictionary<string, bool[]> boolArrayStats;
}
public class StatsUI : MonoBehaviour
{
	public static StatsUI instance;

	public Dictionary<string, float> floatStats;

	public Dictionary<string, int> intStats;

	public Dictionary<string, bool[]> boolArrayStats;

	public Dictionary<string, TextMesh> statTMs;

	private Vector3 lastPosition;

	private string lastPortVisited;

	private int trackerTimer;

	private string lastStorm;

	private void Awake()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		floatStats = new Dictionary<string, float>();
		intStats = new Dictionary<string, int>();
		boolArrayStats = new Dictionary<string, bool[]>();
		statTMs = new Dictionary<string, TextMesh>();
		lastPosition = default(Vector3);
		lastPortVisited = "";
		trackerTimer = 1000;
		lastStorm = "";
		string[] floatStatNames = Names.floatStatNames;
		foreach (string text in floatStatNames)
		{
			floatStats.Add(text, 0f);
			floatStats.Add("current" + text, 0f);
			floatStats.Add("record" + text, 0f);
		}
		string[] intStatNames = Names.intStatNames;
		foreach (string text2 in intStatNames)
		{
			intStats.Add(text2, 0);
			intStats.Add("current" + text2, 0);
			intStats.Add("record" + text2, 0);
		}
		string[] transitNames = Names.transitNames;
		foreach (string text3 in transitNames)
		{
			floatStats.Add("last" + text3 + "TransitTime", 0f);
			intStats.Add("last" + text3 + "TransitDay", 0);
			floatStats.Add("record" + text3 + "TransitTime", 0f);
			intStats.Add("record" + text3 + "TransitDay", 0);
		}
		string[] capitals = Names.capitals;
		foreach (string text4 in capitals)
		{
			floatStats.Add(text4 + "UnderwayTime", 0f);
			intStats.Add(text4 + "UnderwayDay", 0);
			boolArrayStats.Add(text4 + "Transit", new bool[4]);
		}
	}

	public void RegisterCurrentMass()
	{
		Transform currentBoat = GameState.currentBoat;
		if (!((Object)(object)((currentBoat != null) ? currentBoat.parent : null) == (Object)null) || !((Object)(object)GameState.lastBoat == (Object)null))
		{
			GameObject val = (((Object)(object)GameState.currentBoat != (Object)null) ? ((Component)GameState.currentBoat.parent).gameObject : ((Component)GameState.lastBoat).gameObject);
			floatStats["currentCargoMass"] = (from item in Extensions.GetPrivateField<List<ItemRigidbody>>((object)val.GetComponent<BoatMass>(), "itemsOnBoat")
				where (Object)(object)((Component)item.GetShipItem()).GetComponent<Good>() != (Object)null && (((Component)item.GetShipItem()).GetComponent<Good>().sizeDescription.Contains("crate") || ((Component)item.GetShipItem()).GetComponent<Good>().sizeDescription.Contains("package") || ((Component)item.GetShipItem()).GetComponent<Good>().sizeDescription.Contains("barrel"))
				select item).Sum((ItemRigidbody item) => item.GetBody().mass);
		}
	}

	public void RegisterUnderway(string islandName)
	{
		if (islandName == null || islandName == "")
		{
			return;
		}
		if (floatStats["recordCargoMass"] < floatStats["currentCargoMass"])
		{
			floatStats["recordCargoMass"] = floatStats["currentCargoMass"];
		}
		floatStats["UnderwayTime"] = Sun.sun.globalTime;
		intStats["UnderwayDay"] = GameState.day;
		if (islandName.Contains("1 A"))
		{
			floatStats["grcUnderwayTime"] = Sun.sun.globalTime;
			intStats["grcUnderwayDay"] = GameState.day;
			for (int i = 0; i < 4; i++)
			{
				boolArrayStats["grcTransit"][i] = false;
			}
		}
		else if (islandName.Contains("9 E"))
		{
			floatStats["dcUnderwayTime"] = Sun.sun.globalTime;
			intStats["dcUnderwayDay"] = GameState.day;
			for (int j = 0; j < 4; j++)
			{
				boolArrayStats["dcTransit"][j] = false;
			}
		}
		else if (islandName.Contains("15 M"))
		{
			floatStats["faUnderwayTime"] = Sun.sun.globalTime;
			intStats["faUnderwayDay"] = GameState.day;
			for (int k = 0; k < 4; k++)
			{
				boolArrayStats["faTransit"][k] = false;
			}
		}
		else if (islandName.Contains("27 Lagoon"))
		{
			floatStats["kbUnderwayTime"] = Sun.sun.globalTime;
			intStats["kbUnderwayDay"] = GameState.day;
			for (int l = 0; l < 4; l++)
			{
				boolArrayStats["kbTransit"][l] = false;
			}
		}
	}

	public void RegisterMoored(string islandName)
	{
		if (islandName == null || islandName == "")
		{
			return;
		}
		UpdateStats();
		if (intStats["currentUnderwayDay"] > intStats["recordUnderwayDay"] || (intStats["currentUnderwayDay"] == intStats["recordUnderwayDay"] && floatStats["currentUnderwayTime"] > floatStats["recordUnderwayTime"]))
		{
			intStats["recordUnderwayDay"] = intStats["currentUnderwayDay"];
			floatStats["recordUnderwayTime"] = floatStats["currentUnderwayTime"];
		}
		floatStats["UnderwayTime"] = 0f;
		intStats["UnderwayDay"] = 0;
		if (islandName.Contains("1 A"))
		{
			if (!boolArrayStats["dcTransit"][0] && (floatStats["dcUnderwayTime"] > 0f || intStats["dcUnderwayDay"] > 0))
			{
				CheckTransitTime("dc", "DcGrc", 0);
			}
			if (!boolArrayStats["faTransit"][0] && (floatStats["faUnderwayTime"] > 0f || intStats["faUnderwayDay"] > 0))
			{
				CheckTransitTime("fa", "FaGrc", 0);
			}
			if (!boolArrayStats["kbTransit"][0] && (floatStats["kbUnderwayTime"] > 0f || intStats["kbUnderwayDay"] > 0))
			{
				CheckTransitTime("kb", "KbGrc", 0);
			}
		}
		else if (islandName.Contains("9 E"))
		{
			if (!boolArrayStats["grcTransit"][1] && (floatStats["grcUnderwayTime"] > 0f || intStats["grcUnderwayDay"] > 0))
			{
				CheckTransitTime("grc", "GrcDc", 1);
			}
			if (!boolArrayStats["faTransit"][1] && (floatStats["faUnderwayTime"] > 0f || intStats["faUnderwayDay"] > 0))
			{
				CheckTransitTime("fa", "FaDc", 1);
			}
			if (!boolArrayStats["kbTransit"][1] && (floatStats["kbUnderwayTime"] > 0f || intStats["kbUnderwayDay"] > 0))
			{
				CheckTransitTime("kb", "KbDc", 1);
			}
		}
		else if (islandName.Contains("15 M"))
		{
			if (!boolArrayStats["grcTransit"][2] && (floatStats["grcUnderwayTime"] > 0f || intStats["grcUnderwayDay"] > 0))
			{
				CheckTransitTime("grc", "GrcFa", 2);
			}
			if (!boolArrayStats["dcTransit"][2] && (floatStats["dcUnderwayTime"] > 0f || intStats["dcUnderwayDay"] > 0))
			{
				CheckTransitTime("dc", "DcFa", 2);
			}
			if (!boolArrayStats["kbTransit"][2] && (floatStats["kbUnderwayTime"] > 0f || intStats["kbUnderwayDay"] > 0))
			{
				CheckTransitTime("kb", "KbFa", 2);
			}
		}
		else if (islandName.Contains("27 Lagoon"))
		{
			if (!boolArrayStats["grcTransit"][3] && (floatStats["grcUnderwayTime"] > 0f || intStats["grcUnderwayDay"] > 0))
			{
				CheckTransitTime("grc", "GrcKb", 3);
			}
			if (!boolArrayStats["dcTransit"][3] && (floatStats["dcUnderwayTime"] > 0f || intStats["dcUnderwayDay"] > 0))
			{
				CheckTransitTime("dc", "DcKb", 3);
			}
			if (!boolArrayStats["faTransit"][3] && (floatStats["faUnderwayTime"] > 0f || intStats["faUnderwayDay"] > 0))
			{
				CheckTransitTime("fa", "FaKb", 3);
			}
		}
	}

	public void CheckTransitTime(string underwayKey, string transitCode, int destInt)
	{
		int num = GameState.day - intStats[underwayKey + "UnderwayDay"];
		float num2 = Sun.sun.globalTime - floatStats[underwayKey + "UnderwayTime"];
		if (num2 < 0f)
		{
			num2 += 24f;
			num--;
		}
		intStats["last" + transitCode + "TransitDay"] = num;
		floatStats["last" + transitCode + "TransitTime"] = num2;
		if ((intStats["record" + transitCode + "TransitDay"] == 0 && floatStats["record" + transitCode + "TransitTime"] == 0f) || intStats["record" + transitCode + "TransitDay"] > num || (intStats["record" + transitCode + "TransitDay"] == num && floatStats["record" + transitCode + "TransitTime"] > num2))
		{
			intStats["record" + transitCode + "TransitDay"] = num;
			floatStats["record" + transitCode + "TransitTime"] = num2;
			if (Plugin.notificationsEnabled.Value)
			{
				NotificationUiQueue.instance.QueueNotification("Fastest " + AddTo(transitCode) + " time");
			}
		}
		boolArrayStats[underwayKey + "Transit"][destInt] = true;
	}

	public void IncrementIntStat(string statName)
	{
		intStats["current" + statName]++;
	}

	public void UpdatePage()
	{
		UpdateStats();
		UpdateTexts();
	}

	private void UpdateStats()
	{
		if (intStats["UnderwayDay"] > 0 || floatStats["UnderwayTime"] > 0f)
		{
			intStats["currentUnderwayDay"] = GameState.day - intStats["UnderwayDay"];
			floatStats["currentUnderwayTime"] = Sun.sun.globalTime - floatStats["UnderwayTime"];
		}
		if (floatStats["currentUnderwayTime"] < 0f)
		{
			floatStats["currentUnderwayTime"] += 24f;
			intStats["currentUnderwayDay"]--;
		}
	}

	private void UpdateTexts()
	{
		string[] floatStatNames = Names.floatStatNames;
		foreach (string text in floatStatNames)
		{
			switch (text)
			{
			case "UnderwayTime":
				statTMs[text].text = AddSpace(text);
				statTMs["currentUnderwayTime"].text = UnderwayText(intStats["currentUnderwayDay"], floatStats["currentUnderwayTime"]);
				statTMs["recordUnderwayTime"].text = UnderwayText(intStats["recordUnderwayDay"], floatStats["recordUnderwayTime"]);
				break;
			case "CargoMass":
				statTMs[text].text = AddSpace(text);
				statTMs["currentCargoMass"].text = ((floatStats["currentCargoMass"] == 0f) ? "-" : string.Format("{0:#,##0.#} lbs", floatStats["currentCargoMass"]));
				statTMs["recordCargoMass"].text = ((floatStats["recordCargoMass"] == 0f) ? "-" : string.Format("{0:#,##0.#} lbs", floatStats["recordCargoMass"]));
				break;
			case "MilesSailed":
				statTMs[text].text = AddSpace(text);
				if (Plugin.updateMilesSailed.Value == "realtime")
				{
					statTMs["currentMilesSailed"].text = string.Format("{0:#,##0.#}", floatStats["currentMilesSailed"]);
				}
				else
				{
					statTMs["currentMilesSailed"].text = string.Format("{0:#,##0.#}", floatStats["MilesSailed"]);
				}
				break;
			default:
				statTMs[text].text = AddSpace(text);
				statTMs["current" + text].text = floatStats["current" + text].ToString();
				statTMs["record" + text].text = floatStats["record" + text].ToString();
				break;
			}
		}
		string[] intStatNames = Names.intStatNames;
		foreach (string text2 in intStatNames)
		{
			if (!(text2 == "UnderwayDay") && (!(text2 == "FlotsamEncounters") || !((Object)(object)RandomEncounters.pluginInstance == (Object)null)) && (!(text2 == "SeaLifeEncounters") || (!((Object)(object)RandomEncounters.pluginInstance == (Object)null) && RandomEncounters.isSeaLifeEnabled)))
			{
				statTMs[text2].text = AddSpace(text2);
				statTMs["current" + text2].text = string.Format("{0:#,##0}", intStats["current" + text2]);
			}
		}
		string[] transitNames = Names.transitNames;
		foreach (string text3 in transitNames)
		{
			statTMs[text3].text = AddTo(text3);
			statTMs["last" + text3].text = UnderwayText(intStats["last" + text3 + "TransitDay"], floatStats["last" + text3 + "TransitTime"]);
			statTMs["record" + text3].text = UnderwayText(intStats["record" + text3 + "TransitDay"], floatStats["record" + text3 + "TransitTime"]);
		}
	}

	private string UnderwayText(int underwayDay, float underwayTime)
	{
		if (underwayDay == 0 && underwayTime == 0f)
		{
			return "-";
		}
		if (underwayDay > 0)
		{
			string arg = ((underwayDay == 1) ? "Day" : "Days");
			return $"{underwayDay} {arg} {underwayTime:0.0} Hours";
		}
		return $"{underwayTime:0.0} Hours";
	}

	private string AddSpace(string name)
	{
		return Regex.Replace(name, "([a-z])([A-Z])", "$1 $2");
	}

	private string AddTo(string name)
	{
		string text = AddSpace(name);
		return text.ToUpper().Insert(text.IndexOf(' '), " to");
	}

	public void PlayerTeleported()
	{
		Plugin.logger.LogInfo((object)"Player teleported, resetting current transits");
		string[] capitals = Names.capitals;
		foreach (string text in capitals)
		{
			int num = 0;
			for (int j = 0; j < 4; j++)
			{
				if (j != num)
				{
					boolArrayStats[text + "Transit"][j] = true;
				}
				num++;
			}
		}
	}

	public void TrackDistance()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		Vector3 globeCoords = FloatingOriginManager.instance.GetGlobeCoords(GameState.currentBoat);
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(globeCoords.x, 0f, globeCoords.z);
		if (lastPosition == Vector3.zero)
		{
			lastPosition = val;
			return;
		}
		if (trackerTimer > 1)
		{
			trackerTimer--;
			return;
		}
		floatStats["currentMilesSailed"] += Vector3.Distance(lastPosition, val) * 61f;
		lastPosition = val;
		trackerTimer = 1000;
	}

	public void UpdateMilesText()
	{
		floatStats["MilesSailed"] = floatStats["currentMilesSailed"];
	}

	public void IncrementPortVisited(string port)
	{
		if (!(lastPortVisited == port))
		{
			IncrementIntStat("PortsVisited");
			lastPortVisited = port;
		}
	}

	public void IncrementStormsWeathered()
	{
		string name = ((Object)WeatherStorms.instance.GetCurrentStorm()).name;
		if (!(lastStorm == name))
		{
			Plugin.logger.LogDebug((object)("Weathering " + name));
			IncrementIntStat("StormsWeathered");
			lastStorm = name;
		}
	}

	public void ClearLastStorm()
	{
		if (!Utility.IsNullOrWhiteSpace(lastStorm))
		{
			Plugin.logger.LogDebug((object)"Storm cleared");
			lastStorm = "";
		}
	}
}