Decompiled source of DudeWheresMyBoat v1.0.0

DudeWheresMyBoat.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine;

[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("DudeWheresMyBoat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+901b84ab23f2f10926b13865f9b40bb283490874")]
[assembly: AssemblyProduct("DudeWheresMyBoat")]
[assembly: AssemblyTitle("DudeWheresMyBoat")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DudeWheresMyBoat
{
	[BepInPlugin("com.dfg.dudewheresmyboat", "DudeWheresMyBoat", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class DudeWheresMyBoatPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.dfg.dudewheresmyboat";

		public const string PluginName = "DudeWheresMyBoat";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<bool> _Enabled;

		public static ConfigEntry<bool> _TrackCarts;

		public static ConfigEntry<bool> _TrackShips;

		public static ConfigEntry<float> _UpdateInterval;

		private static Dictionary<ZDOID, PinData> _activePins = new Dictionary<ZDOID, PinData>();

		private static List<ZDOID> _trackedZDOs = new List<ZDOID>();

		private Coroutine _trackerCoroutine;

		private static PinType _shipPinType = (PinType)3;

		private static PinType _cartPinType = (PinType)3;

		private static bool _pinsRegistered = false;

		private void Awake()
		{
			_Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Enable tracking of ships and carts on the map");
			_TrackShips = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "TrackShips", true, "Show ships on the map");
			_TrackCarts = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "TrackCarts", true, "Show carts on the map");
			_UpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "UpdateInterval", 3f, "Seconds between map pin updates");
			if (_Enabled.Value)
			{
				_trackerCoroutine = ((MonoBehaviour)this).StartCoroutine(TrackRoutine());
			}
		}

		private void OnDestroy()
		{
			if (_trackerCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_trackerCoroutine);
			}
			ClearPins();
		}

		private static void ClearPins()
		{
			if ((Object)(object)Minimap.instance == (Object)null)
			{
				return;
			}
			foreach (PinData value in _activePins.Values)
			{
				Minimap.instance.RemovePin(value);
			}
			_activePins.Clear();
		}

		private IEnumerator TrackRoutine()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(_UpdateInterval.Value);
				if (_Enabled.Value && ZDOMan.instance != null && (Object)(object)Minimap.instance != (Object)null)
				{
					UpdateVehicleList();
				}
			}
		}

		private void UpdateVehicleList()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			List<ZDO> list = new List<ZDO>();
			if (_TrackShips.Value)
			{
				CollectPrefabZDOs("Karve", list);
				CollectPrefabZDOs("VikingShip", list);
				CollectPrefabZDOs("Raft", list);
				CollectPrefabZDOs("piece_harpoonlongboat", list);
			}
			if (_TrackCarts.Value)
			{
				CollectPrefabZDOs("Cart", list);
			}
			_trackedZDOs.Clear();
			foreach (ZDO item in list)
			{
				if (item.IsValid())
				{
					_trackedZDOs.Add(item.m_uid);
				}
			}
		}

		private void CollectPrefabZDOs(string prefabName, List<ZDO> results)
		{
			int num = 0;
			List<ZDO> list = new List<ZDO>();
			while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(prefabName, list, ref num))
			{
			}
			results.AddRange(list);
		}

		private void Update()
		{
			//IL_007c: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Minimap.instance == (Object)null)
			{
				if (_activePins.Count > 0)
				{
					_activePins.Clear();
				}
				_pinsRegistered = false;
			}
			else
			{
				if (!_Enabled.Value || ZDOMan.instance == null || (Object)(object)ZNetScene.instance == (Object)null)
				{
					return;
				}
				if (!_pinsRegistered)
				{
					RegisterCustomPins();
					_pinsRegistered = true;
				}
				List<ZDOID> list = new List<ZDOID>();
				foreach (KeyValuePair<ZDOID, PinData> activePin in _activePins)
				{
					ZDOID key = activePin.Key;
					PinData value = activePin.Value;
					if (!_trackedZDOs.Contains(key))
					{
						list.Add(key);
						continue;
					}
					ZDO zDO = ZDOMan.instance.GetZDO(key);
					if (zDO == null || !zDO.IsValid())
					{
						list.Add(key);
					}
					else
					{
						value.m_pos = zDO.GetPosition();
					}
				}
				foreach (ZDOID item in list)
				{
					Minimap.instance.RemovePin(_activePins[item]);
					_activePins.Remove(item);
				}
				foreach (ZDOID trackedZDO in _trackedZDOs)
				{
					if (!_activePins.ContainsKey(trackedZDO))
					{
						ZDO zDO2 = ZDOMan.instance.GetZDO(trackedZDO);
						if (zDO2 != null && zDO2.IsValid())
						{
							int prefab = zDO2.GetPrefab();
							string zDOName = GetZDOName(zDO2, prefab);
							PinType pinType = GetPinType(prefab);
							PinData val = Minimap.instance.AddPin(zDO2.GetPosition(), pinType, zDOName, false, false, 0L, default(PlatformUserID));
							val.m_doubleSize = false;
							_activePins[trackedZDO] = val;
						}
					}
				}
			}
		}

		private void RegisterCustomPins()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00db: 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)
			try
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("VikingShip");
				Sprite val = ((prefab == null) ? null : prefab.GetComponent<Piece>()?.m_icon);
				GameObject prefab2 = ZNetScene.instance.GetPrefab("Cart");
				Sprite val2 = ((prefab2 == null) ? null : prefab2.GetComponent<Piece>()?.m_icon);
				if ((Object)(object)val != (Object)null)
				{
					PinType val3 = (PinType)Minimap.instance.m_icons.Count;
					SpriteData item = new SpriteData
					{
						m_name = val3,
						m_icon = val
					};
					Minimap.instance.m_icons.Add(item);
					_shipPinType = val3;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					PinType val4 = (PinType)Minimap.instance.m_icons.Count;
					SpriteData item2 = new SpriteData
					{
						m_name = val4,
						m_icon = val2
					};
					Minimap.instance.m_icons.Add(item2);
					_cartPinType = val4;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to register custom native pins: " + ex.Message));
			}
		}

		private static PinType GetPinType(int prefabHash)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (prefabHash == StringExtensionMethods.GetStableHashCode("Cart"))
			{
				return _cartPinType;
			}
			return _shipPinType;
		}

		private static string GetZDOName(ZDO zdo, int prefabHash)
		{
			if (prefabHash == StringExtensionMethods.GetStableHashCode("Karve"))
			{
				return "Karve";
			}
			if (prefabHash == StringExtensionMethods.GetStableHashCode("VikingShip"))
			{
				return "Longship";
			}
			if (prefabHash == StringExtensionMethods.GetStableHashCode("Raft"))
			{
				return "Raft";
			}
			if (prefabHash == StringExtensionMethods.GetStableHashCode("Cart"))
			{
				return "Cart";
			}
			if (prefabHash == StringExtensionMethods.GetStableHashCode("piece_harpoonlongboat"))
			{
				return "Harpoon Longboat";
			}
			return "Vessel";
		}
	}
}