Decompiled source of Better Cartography Table v0.6.0

plugins/BetterCartographyTable.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetterCartographyTable.Extensions;
using BetterCartographyTable.Model;
using BetterCartographyTable.Model.Managers;
using BetterCartographyTable.Model.MapTableZDOValues;
using BetterCartographyTable.Model.PinClickHandlers;
using BetterCartographyTable.UI;
using Guilds;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("BetterCartographyTable")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyInformationalVersion("0.6.0+f75a41a1c0edc75492e07985058b7fb2c5667003")]
[assembly: AssemblyProduct("BetterCartographyTable")]
[assembly: AssemblyTitle("BetterCartographyTable")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BetterCartographyTable
{
	[BepInPlugin("nbusseneau.BetterCartographyTable", "BetterCartographyTable", "0.6.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string ModGUID = "nbusseneau.BetterCartographyTable";

		private const string ModName = "BetterCartographyTable";

		private const string ModVersion = "0.6.0";

		private static ConfigEntry<SharingMode> s_mapExplorationSharingMode;

		private static ConfigEntry<KeyCode> s_modifierKey;

		private static ConfigEntry<Color> s_publicPinsColor;

		public static ManualLogSource Logger;

		public static SharingMode MapExplorationSharingMode => s_mapExplorationSharingMode.Value;

		public static KeyCode ModifierKey => s_modifierKey.Value;

		public static bool IsModifierKeyPressed => Input.GetKey(ModifierKey);

		public static Color PublicPinsColor => s_publicPinsColor.Value;

		public void Awake()
		{
			//IL_005f: 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)
			Logger = ((BaseUnityPlugin)this).Logger;
			s_mapExplorationSharingMode = ((BaseUnityPlugin)this).Config.Bind<SharingMode>("Behaviour", "Map exploration sharing mode", SharingMode.Public, "Whether to share your own map exploration to cartography tables you interact with.\nNo matter your choice, you will always receive other players' map exploration data (if anything was shared to the table).\n  - Private: never share your map exploration\n  - Public: always share your map exploration with all cartography tables (both public and guild)\n  - Guild: only share your map exploration with guild tables");
			s_modifierKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "Modifier key", (KeyCode)304, "Modifier key to use for interacting with public or guild pins on the cartography table.");
			s_publicPinsColor = ((BaseUnityPlugin)this).Config.Bind<Color>("UI", "Public pins color", Color.green, "Color to use for public pins.");
			SetUpConfigWatcher();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			new Harmony("nbusseneau.BetterCartographyTable").PatchAll(executingAssembly);
		}

		public void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetUpConfigWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath));
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
			{
				return;
			}
			try
			{
				Logger.LogDebug((object)"Attempting to reload configuration...");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Logger.LogError((object)("There was an issue loading " + ((BaseUnityPlugin)this).Config.ConfigFilePath));
			}
		}
	}
}
namespace BetterCartographyTable.UI
{
	public class MapTableCantRemovePopup : YesNoPopup
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static PopupButtonCallback <0>__Pop;
		}

		private MapTableCantRemovePopup(PopupButtonCallback onYesCallback)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			object obj = <>O.<0>__Pop;
			if (obj == null)
			{
				PopupButtonCallback val = UnifiedPopup.Pop;
				<>O.<0>__Pop = val;
				obj = (object)val;
			}
			((YesNoPopup)this)..ctor("$MapTable_CantRemove_PopupHeader", "$MapTable_CantRemove_PopupText", onYesCallback, (PopupButtonCallback)obj, true);
			UnifiedPopup.Push((PopupBase)(object)this);
		}

		public static void Show(Action onYesCallback)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			new MapTableCantRemovePopup((PopupButtonCallback)delegate
			{
				onYesCallback();
				UnifiedPopup.Pop();
			});
		}
	}
	public class MapTableToggleModeWarningPopup : WarningPopup
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static PopupButtonCallback <0>__Pop;
		}

		private MapTableToggleModeWarningPopup()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			object obj = <>O.<0>__Pop;
			if (obj == null)
			{
				PopupButtonCallback val = UnifiedPopup.Pop;
				<>O.<0>__Pop = val;
				obj = (object)val;
			}
			((WarningPopup)this)..ctor("$MapTable_ToggleMode_PopupHeader", "$MapTable_ToggleMode_PopupText", (PopupButtonCallback)obj, true);
			UnifiedPopup.Push((PopupBase)(object)this);
		}

		public static void Show()
		{
			new MapTableToggleModeWarningPopup();
		}
	}
	public class MinimapKeyHint
	{
		private readonly GameObject _gameObject;

		public string Text
		{
			set
			{
				_gameObject.SetText(value);
			}
		}

		public MinimapKeyHint(GameObject keyHint)
		{
			_gameObject = keyHint;
			base..ctor();
		}

		public static MinimapKeyHint Clone(MinimapKeyHint original, string name, string key)
		{
			GameObject val = Object.Instantiate<GameObject>(original._gameObject, original._gameObject.transform.parent);
			((Object)val).name = name;
			val.transform.SetAsFirstSibling();
			Object.Destroy((Object)(object)((Component)val.transform.Find("keyboard_hint")).gameObject);
			GameObject obj = Object.Instantiate<GameObject>(((Component)KeyHints.m_instance.m_buildHints.transform.Find("Keyboard/AltPlace/key_bkg")).gameObject, val.transform);
			((Object)obj).name = "key_bkg";
			obj.SetText(key);
			val.SetActive(false);
			return new MinimapKeyHint(val);
		}

		public void Show(string text = null)
		{
			_gameObject.SetActive(true);
			if (!string.IsNullOrEmpty(text))
			{
				Text = text;
			}
		}

		public void Hide()
		{
			_gameObject.SetActive(false);
		}
	}
	public class MinimapPinsToggle
	{
		private readonly Toggle _toggle;

		public GameObject GameObject { get; private set; }

		public bool IsOn { get; private set; } = true;


		public MinimapPinsToggle(string namePrefix, string labelText)
		{
			GameObject = Object.Instantiate<GameObject>(Minimap.instance.m_sharedMapHint, Minimap.instance.m_sharedMapHint.transform.parent);
			((Object)GameObject).name = namePrefix + "Panel";
			((Object)GameObject.transform.Find("PublicPosition")).name = namePrefix + "Position";
			GameObject.SetText(labelText);
			_toggle = GameObject.GetComponentInChildren<Toggle>();
			((UnityEventBase)_toggle.onValueChanged).SetPersistentListenerState(0, (UnityEventCallState)0);
			((UnityEvent<bool>)(object)_toggle.onValueChanged).AddListener((UnityAction<bool>)OnToggle);
			ForceToggleOn();
			Show();
		}

		private void OnToggle(bool isOn)
		{
			IsOn = isOn;
			Minimap.instance.m_pinUpdateRequired = true;
		}

		public void ForceToggleOn()
		{
			_toggle.isOn = true;
			OnToggle(_toggle.isOn);
		}

		public void Show()
		{
			GameObject.SetActive(true);
		}

		public void Hide()
		{
			GameObject.SetActive(false);
		}
	}
	public static class MinimapUI
	{
		private static class Toggles
		{
			public static MinimapPinsToggle PublicPins { get; set; }

			public static MinimapPinsToggle GuildPins { get; set; }
		}

		private static class KeyHints
		{
			public static MinimapKeyHint DoubleClick { get; set; }

			public static MinimapKeyHint LeftClick { get; set; }

			public static MinimapKeyHint RightClick { get; set; }

			public static MinimapKeyHint ModifierKey { get; set; }
		}

		private static List<GameObject> s_toggles;

		private static int s_togglesLastCheckActiveCount = -1;

		public static void PrepareToggles()
		{
			Toggles.PublicPins = new MinimapPinsToggle("PublicPins", "$PinsToggle_PublicPins");
			Toggles.GuildPins = new MinimapPinsToggle("GuildPins", "$PinsToggle_GuildPins");
			s_toggles = new List<GameObject>(4)
			{
				((Component)Minimap.instance.m_publicPosition).gameObject,
				Minimap.instance.m_sharedMapHint,
				Toggles.PublicPins.GameObject,
				Toggles.GuildPins.GameObject
			};
		}

		public static void PrepareKeyHints()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = Minimap.instance.m_hints[0].transform;
			KeyHints.DoubleClick = new MinimapKeyHint(((Component)transform.Find("keyboard_hints/AddPin")).gameObject);
			KeyHints.LeftClick = new MinimapKeyHint(((Component)transform.Find("keyboard_hints/CrossOffPin")).gameObject);
			KeyHints.RightClick = new MinimapKeyHint(((Component)transform.Find("keyboard_hints/RemovePin")).gameObject);
			KeyHints.ModifierKey = MinimapKeyHint.Clone(KeyHints.DoubleClick, "ModifierKey", Plugin.ModifierKey.ToKeyHintString());
		}

		public static void ShowTableUI()
		{
			if (MapTableManager.CurrentTable.IsPublic)
			{
				Toggles.PublicPins.ForceToggleOn();
				Toggles.PublicPins.Show();
			}
			else if (MapTableManager.CurrentTable.IsGuild)
			{
				Toggles.GuildPins.ForceToggleOn();
				Toggles.GuildPins.Show();
			}
			KeyHints.ModifierKey.Show();
		}

		public static void HideTableUI()
		{
			if (!MinimapManager.PublicPins.Any())
			{
				Toggles.PublicPins.Hide();
			}
			if (!MinimapManager.GuildPins.Any())
			{
				Toggles.GuildPins.Hide();
			}
			KeyHints.ModifierKey.Hide();
		}

		public static void UpdateToggles()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			IEnumerable<GameObject> source = s_toggles.Where((GameObject gameObject) => gameObject.activeInHierarchy);
			int num = source.Count();
			if (!source.Any() || s_togglesLastCheckActiveCount == num)
			{
				return;
			}
			s_togglesLastCheckActiveCount = num;
			Vector3 position = source.First().transform.position;
			int num2 = 1;
			float num3 = Minimap.instance.m_sharedMapHint.transform.position.y - ((Component)Minimap.instance.m_publicPosition).transform.position.y;
			foreach (GameObject item in source.Skip(1))
			{
				Vector3 position2 = item.transform.position;
				item.transform.position = new Vector3(position2.x, position.y + num3 * (float)num2, position2.z);
				num2++;
			}
		}

		public static void UpdateKeyHints()
		{
			if (!MapTableManager.IsTableValid)
			{
				KeyHints.DoubleClick.Show("$hud_addpin");
				KeyHints.LeftClick.Text = "$hud_crossoffpin";
				KeyHints.RightClick.Text = "$hud_removepin";
				return;
			}
			if (!Plugin.IsModifierKeyPressed)
			{
				KeyHints.DoubleClick.Show("$KeyHint_AddPrivatePin");
				KeyHints.LeftClick.Text = "$hud_crossoffpin";
				KeyHints.RightClick.Text = "$KeyHint_RemovePrivatePin";
			}
			else
			{
				KeyHints.DoubleClick.Hide();
				KeyHints.LeftClick.Text = "$KeyHint_ToggleSharing";
				KeyHints.RightClick.Text = (MapTableManager.CurrentTable.IsGuild ? "$KeyHint_RemoveGuildPin" : "$KeyHint_RemovePublicPin");
			}
			KeyHints.ModifierKey.Text = (MapTableManager.CurrentTable.IsGuild ? "$KeyHint_GuildModifierKey" : "$KeyHint_PublicModifierKey");
		}

		public static void UpdateSharedPins()
		{
			//IL_0031: 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)
			foreach (SharablePinData publicPin in MinimapManager.PublicPins)
			{
				publicPin.SetVisibility(Toggles.PublicPins.IsOn);
				if (Toggles.PublicPins.IsOn)
				{
					publicPin.SetColor(Plugin.PublicPinsColor);
				}
			}
			foreach (SharablePinData guildPin in MinimapManager.GuildPins)
			{
				guildPin.SetVisibility(Toggles.GuildPins.IsOn);
				if (Toggles.GuildPins.IsOn)
				{
					guildPin.SetColor(GuildsManager.CurrentGuildColor);
				}
			}
		}
	}
}
namespace BetterCartographyTable.Patches
{
	[HarmonyPatch(typeof(Game))]
	public static class GamePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("RequestRespawn")]
		private static void InitializeGuildsManager()
		{
			GuildsManager.Initialize();
		}
	}
	[HarmonyPatch(typeof(MapTable))]
	public static class MapTablePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void RegisterMapTable(MapTable __instance)
		{
			MapTableManager.Add(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		[HarmonyPatch("OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData),
			typeof(bool)
		})]
		[HarmonyPatch("OnWrite", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static void OnUse(MapTable __instance, Humanoid user, ItemData item, ref bool __result, ref bool __runOriginal)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			__runOriginal = false;
			bool num = item != null;
			bool flag = !__instance.m_nview.IsValid();
			if (num || flag)
			{
				__result = false;
				return;
			}
			if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
			{
				__result = true;
				return;
			}
			MapTableManager.TryOpen(__instance, user);
			__result = true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("GetReadHoverText")]
		[HarmonyPatch("GetWriteHoverText")]
		private static void GetHoverText(MapTable __instance, ref string __result, ref bool __runOriginal)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			__runOriginal = false;
			if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
			{
				__result = Localization.instance.Localize(__instance.m_name + "\n$piece_noaccess");
				return;
			}
			string hoverText = MapTableManager.GetHoverText(__instance);
			__result = Localization.instance.Localize(hoverText);
		}
	}
	[HarmonyPatch(typeof(Minimap))]
	public static class MinimapPatches
	{
		[HarmonyPatch(typeof(Minimap), "SetMapMode")]
		private class OnSetMapMode
		{
			private static bool s_noMap;

			private static void Prefix(MapMode mode)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Invalid comparison between Unknown and I4
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Invalid comparison between Unknown and I4
				s_noMap = Game.m_noMap;
				if ((int)mode == 2 && MapTableManager.IsTableValid && s_noMap)
				{
					Game.m_noMap = false;
				}
				if ((int)mode == 1)
				{
					MapTableManager.TryClose();
				}
			}

			private static void Postfix()
			{
				if (s_noMap)
				{
					Game.m_noMap = true;
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "GetMapData")]
		private class InjectPrivatePinsInSaveFile
		{
			private static List<PinData> s_privatePins;

			private static void Prefix()
			{
				s_privatePins = MinimapManager.PrivatePins.ToList();
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				return new CodeMatcher(instructions, (ILGenerator)null).MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Minimap), "m_pins"), (string)null)
				}).ThrowIfInvalid("Could not inject pins replacement in Minimap.GetMapData()").Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					m.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(InjectPrivatePinsInSaveFile), "s_privatePins"));
				}, (Action<string>)null)
					.InstructionEnumeration();
			}
		}

		[HarmonyPatch(typeof(Minimap), "GetSharedMapData")]
		private class EditOutboundVanillaSharedMapData
		{
			private static bool s_shouldShareMapExploration;

			private static List<PinData> s_pins;

			private static void Prefix()
			{
				s_shouldShareMapExploration = Plugin.MapExplorationSharingMode == SharingMode.Public || (Plugin.MapExplorationSharingMode == SharingMode.Guild && MapTableManager.CurrentTable.IsGuild);
				s_pins = (MapTableManager.CurrentTable.IsPublic ? ((IEnumerable<PinData>)MinimapManager.PublicPins).ToList() : new List<PinData>());
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Expected O, but got Unknown
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Expected O, but got Unknown
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Expected O, but got Unknown
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Expected O, but got Unknown
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Expected O, but got Unknown
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b1: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchEndForward((CodeMatch[])(object)new CodeMatch[5]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Minimap), "m_explored"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldlen, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Conv_I4, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null)
				}).ThrowIfInvalid("Could not inject conditional branching over m_explored sharing loop in Minimap.GetSharedMapData()").InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null)
				})
					.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<ZPackage, bool>>((Func<ZPackage, bool>)delegate(ZPackage zPackage)
					{
						if (!s_shouldShareMapExploration)
						{
							for (int i = 0; i < Minimap.instance.m_explored.Length; i++)
							{
								zPackage.Write(false);
							}
						}
						return s_shouldShareMapExploration;
					}) });
				int pos = val.Pos;
				val.MatchStartForward((CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Stloc_2, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Minimap), "m_pins"), (string)null)
				}).ThrowIfInvalid("Could not inject conditional branching over m_explored sharing loop in Minimap.GetSharedMapData()");
				int pos2 = val.Pos;
				val.Advance(pos - pos2).InsertBranchAndAdvance(OpCodes.Brfalse_S, pos2);
				val.Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Minimap), "m_pins"), (string)null)
				}).ThrowIfInvalid("Could not inject m_pins replacement in Minimap.GetSharedMapData()")
					.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
					{
						m.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(EditOutboundVanillaSharedMapData), "s_pins"));
					}, (Action<string>)null);
				return val.InstructionEnumeration();
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("AddPin")]
		private static IEnumerable<CodeInstruction> EnforceSharablePinDataInAddPin(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: 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_0031: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Newobj, (object)AccessTools.Constructor(typeof(PinData), (Type[])null, false), (string)null)
			}).ThrowIfInvalid("Could not patch PinData constructor in Minimap.AddPin(...)").SetOperandAndAdvance((object)AccessTools.Constructor(typeof(SharablePinData), (Type[])null, false))
				.InstructionEnumeration();
		}

		[HarmonyPostfix]
		[HarmonyPatch("AddPin")]
		private static void AlwaysAddPinAsLocal(ref PinData __result)
		{
			__result.m_ownerID = 0L;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnMapDblClick")]
		private static void InterceptOnMapDblClick(ref bool __runOriginal)
		{
			__runOriginal = !Plugin.IsModifierKeyPressed;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnMapLeftClick")]
		private static void InterceptOnMapLeftClick(ref bool __runOriginal)
		{
			__runOriginal = false;
			MinimapManager.HandleClick(Plugin.IsModifierKeyPressed ? ClickType.LeftClickPlusModifier : ClickType.LeftClick);
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnMapRightClick")]
		private static void InterceptOnMapRightClick(ref bool __runOriginal)
		{
			__runOriginal = false;
			MinimapManager.HandleClick(Plugin.IsModifierKeyPressed ? ClickType.RightClickPlusModifier : ClickType.RightClick);
		}

		[HarmonyTranspiler]
		[HarmonyPatch("AddSharedMapData")]
		private static IEnumerable<CodeInstruction> TruncateInboundVanillaSharedMapData(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchStartForward((CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_2, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Blt, (object)null, (string)null)
			}).ThrowIfInvalid("Could not truncate Minimap.AddSharedMapData()").SetAndAdvance(OpCodes.Ldloc_3, (object)null)
				.SetAndAdvance(OpCodes.Ret, (object)null)
				.InstructionEnumeration();
		}

		[HarmonyPostfix]
		[HarmonyPatch("Reset")]
		private static void PrepareTogglesAndKeyHints()
		{
			MinimapUI.PrepareToggles();
			MinimapUI.PrepareKeyHints();
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateMap")]
		private static void UpdateTogglesAndKeyHints()
		{
			MinimapUI.UpdateToggles();
			MinimapUI.UpdateKeyHints();
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdatePins")]
		private static void UpdateSharedPins()
		{
			MinimapUI.UpdateSharedPins();
		}

		[HarmonyPostfix]
		[HarmonyPatch("AddSharedMapData")]
		[HarmonyPatch("ResetAndExplore")]
		private static void ShowCartographyToggle()
		{
			if (Minimap.instance.m_exploredOthers.Length != 0)
			{
				Minimap.instance.m_sharedMapHint.SetActive(true);
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	public static class PlayerPatches
	{
		[HarmonyPatch(typeof(Player), "RemovePiece")]
		private class IsRemovingPiece
		{
			private static void Prefix()
			{
				s_isRemovingPiece = true;
			}

			private static void Postfix()
			{
				s_isRemovingPiece = false;
			}
		}

		private const string PinsCustomDataKey = "nbusseneau.BetterCartographyTable.Pins";

		private static bool s_isRemovingPiece;

		private static bool s_shouldForceRemoveMapTable;

		private static string CurrentWorldPinsCustomDataKey => string.Format("{0}.{1}", "nbusseneau.BetterCartographyTable.Pins", ZNet.instance.GetWorldUID());

		[HarmonyPrefix]
		[HarmonyPatch("Save")]
		private static void SaveSharedPins(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				string @base = MinimapManager.SharedPins.ToCompressedZPackage().GetBase64();
				__instance.m_customData[CurrentWorldPinsCustomDataKey] = @base;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Load")]
		private static void LoadSharedPins(Player __instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && Game.instance.m_firstSpawn)
			{
				if (__instance.m_customData.TryGetValue(CurrentWorldPinsCustomDataKey, out var value))
				{
					MinimapManager.AddPins(ZPackageExtensions.Decompress(new ZPackage(value)).ReadSharablePinDataList());
				}
				MinimapUI.HideTableUI();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateStations")]
		private static void CloseMapWhenTooFarFromTable(Player __instance)
		{
			if (MapTableManager.IsTableValid && !MapTableManager.CurrentTable.IsInUseDistance(__instance))
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("CheckCanRemovePiece")]
		private static void CheckCanRemoveMapTable(Player __instance, Piece piece, ref bool __result, ref bool __runOriginal)
		{
			if (!s_isRemovingPiece)
			{
				return;
			}
			if (s_shouldForceRemoveMapTable)
			{
				s_shouldForceRemoveMapTable = false;
				return;
			}
			MapTable component = ((Component)piece).GetComponent<MapTable>();
			if (component == null)
			{
				return;
			}
			MapTableManager mapTableManager = MapTableManager.Get(component);
			if ((object)mapTableManager != null && mapTableManager.Pins.Any())
			{
				__runOriginal = false;
				__result = false;
				MapTableCantRemovePopup.Show(delegate
				{
					s_shouldForceRemoveMapTable = true;
					__instance.RemovePiece();
				});
			}
		}
	}
	[HarmonyPatch(typeof(ZNetScene))]
	public static class ZNetScenePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Destroy")]
		private static void TryRemoveMapTableManagersOnDestroy(GameObject go)
		{
			ZNetView component = go.GetComponent<ZNetView>();
			if (component != null && component.GetZDO() != null)
			{
				MapTableManager.Remove(component);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnZDODestroyed")]
		private static void TryRemoveMapTableManagersOnZDODestroyed(ZDO zdo)
		{
			if (ZNetScene.instance.m_instances.TryGetValue(zdo, out var value))
			{
				MapTableManager.Remove(value);
			}
		}
	}
}
namespace BetterCartographyTable.Model
{
	public enum PinEvent
	{
		Add,
		ToggleChecked,
		Remove
	}
	public class SharablePinData : PinData, IEquatable<PinData>
	{
		private static readonly HashSet<PinType> s_sharablePinTypes = new HashSet<PinType>
		{
			(PinType)0,
			(PinType)1,
			(PinType)2,
			(PinType)3,
			(PinType)6,
			(PinType)9,
			(PinType)14,
			(PinType)15,
			(PinType)16
		};

		public SharingMode SharingMode { get; set; }

		public bool IsPrivate => SharingMode == SharingMode.Private;

		public bool IsShared => !IsPrivate;

		public bool IsPublic => SharingMode == SharingMode.Public;

		public bool IsGuild => SharingMode == SharingMode.Guild;

		public static bool IsSharable(PinData pin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return s_sharablePinTypes.Contains(pin.m_type);
		}

		public SharablePinData()
		{
		}

		public SharablePinData(PinData pin)
		{
			//IL_0014: 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)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			base.m_name = pin.m_name;
			base.m_type = pin.m_type;
			base.m_pos = pin.m_pos;
			base.m_ownerID = pin.m_ownerID;
			base.m_author = pin.m_author;
			base.m_checked = pin.m_checked;
		}

		public override string ToString()
		{
			//IL_0025: 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)
			return string.Format("{0} {1} {2} {3} {4} {5}L {6}", SharingMode, base.m_name, base.m_pos, base.m_checked ? "⦻" : "⭘", base.m_author, base.m_ownerID, Enum.GetName(typeof(PinType), base.m_type));
		}

		public void SetVisibility(bool isVisible)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			RectTransform uiElement = base.m_uiElement;
			if (uiElement != null)
			{
				GameObject gameObject = ((Component)uiElement).gameObject;
				if (gameObject != null)
				{
					gameObject.SetActive(isVisible);
				}
			}
			if ((int)Minimap.instance.m_mode != 2)
			{
				return;
			}
			PinNameData namePinData = base.m_NamePinData;
			if (namePinData != null)
			{
				GameObject pinNameGameObject = namePinData.PinNameGameObject;
				if (pinNameGameObject != null)
				{
					pinNameGameObject.SetActive(isVisible);
				}
			}
		}

		public void SetColor(Color color)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Image iconElement = base.m_iconElement;
			if (iconElement != null)
			{
				((Graphic)iconElement).color = color;
			}
			PinNameData namePinData = base.m_NamePinData;
			TMP_Text val = ((namePinData != null) ? namePinData.PinNameText : null);
			if (val != null)
			{
				((Graphic)val).color = color;
			}
		}

		public ZPackage ToCompressedZPackage()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0011: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			ZPackageExtensions.Write(val, this);
			return ZPackageExtensions.Compress(val);
		}

		public bool Equals(PinData other)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (other == null)
			{
				return false;
			}
			if ((object)this == other)
			{
				return true;
			}
			return ((Vector3)(ref base.m_pos)).Equals(other.m_pos);
		}

		public override bool Equals(object obj)
		{
			return Equals((PinData)((obj is PinData) ? obj : null));
		}

		public static bool operator ==(SharablePinData a, PinData b)
		{
			if ((object)a != b)
			{
				return a?.Equals(b) ?? false;
			}
			return true;
		}

		public static bool operator !=(SharablePinData a, PinData b)
		{
			return !(a == b);
		}

		public override int GetHashCode()
		{
			return ((object)(Vector3)(ref base.m_pos)).GetHashCode();
		}
	}
	public enum SharingMode
	{
		Private,
		Public,
		Guild
	}
}
namespace BetterCartographyTable.Model.PinClickHandlers
{
	public enum ClickType
	{
		LeftClick,
		LeftClickPlusModifier,
		RightClick,
		RightClickPlusModifier
	}
	public class MapTablePinClickHandler
	{
		public static void Dispatch(ClickType clickType, SharablePinData pin)
		{
			switch (clickType)
			{
			case ClickType.LeftClick:
				LeftClick(pin);
				break;
			case ClickType.LeftClickPlusModifier:
				LeftClickPlusModifier(pin);
				break;
			case ClickType.RightClickPlusModifier:
				RightClickPlusModifier(pin);
				break;
			}
		}

		public static void LeftClick(SharablePinData pin)
		{
			((PinData)(object)pin).ToggleChecked();
			MapTableManager.CurrentTable.SendPinEvent(pin, PinEvent.ToggleChecked);
		}

		public static void LeftClickPlusModifier(SharablePinData pin)
		{
			pin.SharingMode = SharingMode.Private;
			Minimap.instance.m_pinUpdateRequired = true;
			MapTableManager.CurrentTable.SendPinEvent(pin, PinEvent.Remove);
		}

		public static void RightClickPlusModifier(SharablePinData pin)
		{
			Minimap.instance.RemovePin((PinData)(object)pin);
			MapTableManager.CurrentTable.SendPinEvent(pin, PinEvent.Remove);
		}
	}
	public class PrivatePinClickHandler
	{
		public static void Dispatch(ClickType clickType, PinData pin)
		{
			switch (clickType)
			{
			case ClickType.LeftClick:
				LeftClick(pin);
				break;
			case ClickType.RightClick:
				RightClick(pin);
				break;
			case ClickType.LeftClickPlusModifier:
				LeftClickPlusModifier(pin);
				break;
			}
		}

		private static void LeftClick(PinData pin)
		{
			pin.ToggleChecked();
		}

		public static void LeftClickPlusModifier(PinData pin)
		{
			if (MapTableManager.IsTableValid && pin.IsSharable())
			{
				SharablePinData sharablePin = pin as SharablePinData;
				if ((object)sharablePin != null || MinimapManager.TryConvert(pin, out sharablePin))
				{
					sharablePin.SharingMode = MapTableManager.CurrentTable.SharingMode;
					Minimap.instance.m_pinUpdateRequired = true;
					MapTableManager.CurrentTable.SendPinEvent(sharablePin, PinEvent.Add);
				}
			}
		}

		public static void RightClick(PinData pin)
		{
			Minimap.instance.RemovePin(pin);
		}
	}
}
namespace BetterCartographyTable.Model.MapTableZDOValues
{
	public class MapTableZDOOwner : MapTableZDOValue<string>
	{
		public override string Value
		{
			get
			{
				return base.NView.GetZDO().GetString(_key, string.Empty);
			}
			set
			{
				if (base.NView.IsOwner())
				{
					base.NView.GetZDO().Set(_key, value);
					return;
				}
				base.NView.InvokeRPC(_storeRPC, new object[1] { value });
			}
		}

		public MapTableZDOOwner(MapTable mapTable)
			: base(mapTable, "Owner")
		{
		}

		protected override void RegisterStoreRPC()
		{
			base.NView.Register<string>(_storeRPC, (Action<long, string>)delegate(long _, string owner)
			{
				RPC_Store(owner);
			});
		}

		private void RPC_Store(string owner)
		{
			if (base.NView.IsOwner())
			{
				base.NView.GetZDO().Set(_key, owner);
			}
		}
	}
	public class MapTableZDOPins : MapTableZDOValue<IEnumerable<SharablePinData>>
	{
		public override IEnumerable<SharablePinData> Value
		{
			get
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				byte[] byteArray = base.NView.GetZDO().GetByteArray(_key, (byte[])null);
				if (byteArray != null)
				{
					byteArray = Utils.Decompress(byteArray);
					return ZPackageExtensions.ReadSharablePinDataList(new ZPackage(byteArray));
				}
				return Array.Empty<SharablePinData>();
			}
			set
			{
				ZPackage val = value.ToCompressedZPackage();
				if (base.NView.IsOwner())
				{
					base.NView.GetZDO().Set(_key, val.GetArray());
					return;
				}
				base.NView.InvokeRPC(_storeRPC, new object[1] { val });
			}
		}

		public MapTableZDOPins(MapTable mapTable)
			: base(mapTable, "Pins")
		{
		}

		protected override void RegisterStoreRPC()
		{
			base.NView.Register<ZPackage>(_storeRPC, (Action<long, ZPackage>)delegate(long _, ZPackage compressedZPackage)
			{
				RPC_Store(compressedZPackage);
			});
		}

		private void RPC_Store(ZPackage compressedZPackage)
		{
			if (base.NView.IsOwner())
			{
				base.NView.GetZDO().Set(_key, compressedZPackage.GetArray());
			}
		}
	}
	public class MapTableZDOSharingMode : MapTableZDOValue<SharingMode>
	{
		public override SharingMode Value
		{
			get
			{
				return (SharingMode)base.NView.GetZDO().GetInt(_key, 1);
			}
			set
			{
				if (base.NView.IsOwner())
				{
					base.NView.GetZDO().Set(_key, (int)value);
					return;
				}
				base.NView.InvokeRPC(_storeRPC, new object[1] { (int)value });
			}
		}

		public MapTableZDOSharingMode(MapTable mapTable)
			: base(mapTable, "Mode")
		{
		}

		protected override void RegisterStoreRPC()
		{
			base.NView.Register<int>(_storeRPC, (Action<long, int>)delegate(long _, int mode)
			{
				RPC_Store(mode);
			});
		}

		private void RPC_Store(int mode)
		{
			if (base.NView.IsOwner())
			{
				base.NView.GetZDO().Set(_key, mode);
			}
		}
	}
	public abstract class MapTableZDOValue<T>
	{
		protected readonly MapTable _mapTable;

		protected readonly string _key;

		protected readonly string _storeRPC;

		protected ZNetView NView => _mapTable.m_nview;

		public abstract T Value { get; set; }

		public MapTableZDOValue(MapTable mapTable, string key)
		{
			_mapTable = mapTable;
			_key = "nbusseneau.BetterCartographyTable.MapTable." + key;
			_storeRPC = "nbusseneau.BetterCartographyTable.RPC_Store.MapTable." + key;
			RegisterStoreRPC();
		}

		protected abstract void RegisterStoreRPC();
	}
}
namespace BetterCartographyTable.Model.Managers
{
	public static class GuildsManager
	{
		private static readonly Color s_fallbackColor = new Color(1f, 61f / 85f, 49f / 136f);

		private static Color? s_currentGuildColor = null;

		public static bool IsEnabled { get; private set; } = false;


		public static Guild CurrentGuild { get; private set; } = null;


		public static Color CurrentGuildColor => (Color)(((??)s_currentGuildColor) ?? TrySetGuildColor());

		public static void Initialize()
		{
			IsEnabled = API.IsLoaded();
			if (!IsEnabled)
			{
				return;
			}
			Guild ownGuild = API.GetOwnGuild();
			if (ownGuild != null)
			{
				Register(ownGuild);
			}
			API.RegisterOnGuildJoined(delegate(Guild guild, PlayerReference player)
			{
				if (player == PlayerReference.forOwnPlayer())
				{
					Register(guild);
				}
			});
			API.RegisterOnGuildLeft(delegate(Guild _, PlayerReference player)
			{
				if (player == PlayerReference.forOwnPlayer())
				{
					Unregister();
				}
			});
		}

		private static void Register(Guild guild)
		{
			CurrentGuild = guild;
		}

		private static void Unregister()
		{
			CurrentGuild = null;
			s_currentGuildColor = null;
			MinimapManager.RemovePins(MinimapManager.GuildPins);
		}

		private static Color TrySetGuildColor()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			Color val = default(Color);
			if (CurrentGuild != null && ColorUtility.TryParseHtmlString(CurrentGuild.General.color, ref val))
			{
				s_currentGuildColor = val;
				return val;
			}
			return s_fallbackColor;
		}
	}
	public class MapTableManager : IEquatable<MapTable>
	{
		private static readonly Dictionary<MapTable, MapTableManager> s_byMapTable = new Dictionary<MapTable, MapTableManager>();

		private static readonly Dictionary<ZNetView, MapTableManager> s_byZNetView = new Dictionary<ZNetView, MapTableManager>();

		private readonly MapTable _mapTable;

		private readonly MapTableZDOPins _pins;

		private readonly MapTableZDOSharingMode _sharingMode;

		private readonly MapTableZDOOwner _owner;

		private const string OnPinEventRPC = "nbusseneau.BetterCartographyTable.RPC_OnPinEvent";

		public static MapTableManager CurrentTable { get; private set; }

		public static bool IsTableValid
		{
			get
			{
				if ((object)CurrentTable != null)
				{
					return CurrentTable.NView.IsValid();
				}
				return false;
			}
		}

		private ZNetView NView => _mapTable.m_nview;

		public bool IsValid
		{
			get
			{
				bool? obj;
				if ((object)this == null)
				{
					obj = null;
				}
				else
				{
					ZNetView nView = NView;
					obj = ((nView != null) ? new bool?(nView.IsValid()) : null);
				}
				bool? flag = obj;
				return flag.GetValueOrDefault();
			}
		}

		private Vector3 Position => ((Component)_mapTable).transform.position;

		public IEnumerable<SharablePinData> Pins
		{
			get
			{
				return _pins.Value;
			}
			private set
			{
				_pins.Value = value;
			}
		}

		public SharingMode SharingMode
		{
			get
			{
				return _sharingMode.Value;
			}
			private set
			{
				_sharingMode.Value = value;
			}
		}

		public bool IsPublic => SharingMode == SharingMode.Public;

		public bool IsGuild => SharingMode == SharingMode.Guild;

		public string Owner
		{
			get
			{
				return _owner.Value;
			}
			private set
			{
				_owner.Value = value;
			}
		}

		public static void Add(MapTable mapTable)
		{
			Dictionary<MapTable, MapTableManager> dictionary = s_byMapTable;
			MapTableManager value = (s_byZNetView[mapTable.m_nview] = new MapTableManager(mapTable));
			dictionary[mapTable] = value;
		}

		public static MapTableManager Get(MapTable mapTable)
		{
			if (!s_byMapTable.TryGetValue(mapTable, out var value))
			{
				return null;
			}
			if (!value.IsValid)
			{
				Remove(value);
				return null;
			}
			return value;
		}

		public static void Remove(ZNetView nview)
		{
			if (s_byZNetView.TryGetValue(nview, out var value))
			{
				Remove(value);
			}
		}

		private static void Remove(MapTableManager mapTableManager)
		{
			if ((object)CurrentTable == mapTableManager)
			{
				CurrentTable = null;
				Minimap.instance.SetMapMode((MapMode)1);
			}
			s_byMapTable.Remove(mapTableManager._mapTable);
			s_byZNetView.Remove(mapTableManager.NView);
		}

		public static void TryOpen(MapTable mapTable, Humanoid user)
		{
			if ((object)CurrentTable != null)
			{
				return;
			}
			MapTableManager mapTableManager = Get(mapTable);
			if ((object)mapTableManager != null)
			{
				if (!mapTableManager.CheckAccess())
				{
					((Character)user).Message((MessageType)2, Localization.instance.Localize("$piece_noaccess"), 0, (Sprite)null);
					return;
				}
				if (Plugin.IsModifierKeyPressed && GuildsManager.IsEnabled)
				{
					mapTableManager.TryToggleMode(user);
					return;
				}
				CurrentTable = mapTableManager;
				CurrentTable.Open();
			}
		}

		public static void TryClose()
		{
			if ((object)CurrentTable != null)
			{
				CurrentTable.Close();
				CurrentTable = null;
			}
		}

		public static string GetHoverText(MapTable mapTable)
		{
			MapTableManager mapTableManager = Get(mapTable);
			if ((object)mapTableManager == null)
			{
				return mapTable.m_name;
			}
			return mapTableManager.GetHoverText();
		}

		public MapTableManager(MapTable mapTable)
		{
			_mapTable = mapTable;
			_pins = new MapTableZDOPins(_mapTable);
			_sharingMode = new MapTableZDOSharingMode(_mapTable);
			_owner = new MapTableZDOOwner(_mapTable);
			NView.Register<ZPackage, int>("nbusseneau.BetterCartographyTable.RPC_OnPinEvent", (Action<long, ZPackage, int>)RPC_OnPinEvent);
		}

		public bool IsInUseDistance(Player player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(((Component)player).transform.position, Position) <= player.m_maxInteractDistance + 1.75f;
		}

		private bool CheckAccess()
		{
			string owner = Owner;
			bool flag = !string.IsNullOrEmpty(owner) && owner == GuildsManager.CurrentGuild?.Name;
			if (!IsPublic)
			{
				return IsGuild && flag;
			}
			return true;
		}

		public string GetHoverText()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			string text = _mapTable.m_name + "\n";
			text += (IsGuild ? ("$MapTable_HoverText_RestrictedToGuild: " + Owner) : "$MapTable_HoverText_Public");
			if (!CheckAccess())
			{
				return text;
			}
			text += "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use";
			if (!GuildsManager.IsEnabled)
			{
				return text;
			}
			string text2 = (IsGuild ? "$MapTable_HoverText_MakePublic" : "$MapTable_HoverText_RestrictToGuild");
			return text + "\n[<b><color=yellow>" + Plugin.ModifierKey.ToKeyHintString() + "</color> + <color=yellow>$KEY_Use</color></b>] " + text2;
		}

		private void TryToggleMode(Humanoid user)
		{
			if (IsPublic && string.IsNullOrEmpty(GuildsManager.CurrentGuild?.Name))
			{
				((Character)user).Message((MessageType)2, Localization.instance.Localize("$MapTable_ToggleMode_GuildRequired"), 0, (Sprite)null);
			}
			else if (Pins.Any())
			{
				MapTableToggleModeWarningPopup.Show();
			}
			else
			{
				ToggleMode();
			}
		}

		private void ToggleMode()
		{
			if (IsPublic)
			{
				RestrictToGuild(GuildsManager.CurrentGuild.Name);
			}
			else if (IsGuild)
			{
				MakePublic();
			}
		}

		private void MakePublic()
		{
			MinimapManager.RemovePins(Pins);
			Pins = Array.Empty<SharablePinData>();
			SharingMode = SharingMode.Public;
			Owner = string.Empty;
		}

		private void RestrictToGuild(string guildName)
		{
			MinimapManager.RemovePins(Pins);
			Pins = Array.Empty<SharablePinData>();
			SharingMode = SharingMode.Guild;
			Owner = guildName;
		}

		private void Open()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			UpdateMinimapPins();
			MinimapManager.RemoveDuplicateLocalPins();
			SyncVanillaSharedMapData();
			MinimapUI.ShowTableUI();
			Minimap.instance.ShowPointOnMap(Position);
		}

		private void Close()
		{
			SaveTablePins();
			SyncVanillaSharedMapData();
			MinimapUI.HideTableUI();
		}

		private void UpdateMinimapPins()
		{
			if (IsPublic)
			{
				MinimapManager.PublicPins = Pins;
			}
			else if (IsGuild)
			{
				MinimapManager.GuildPins = Pins;
			}
		}

		private void SaveTablePins()
		{
			if (IsPublic)
			{
				Pins = MinimapManager.PublicPins;
			}
			else if (IsGuild)
			{
				Pins = MinimapManager.GuildPins;
			}
		}

		public void SendPinEvent(SharablePinData pin, PinEvent pinEvent)
		{
			NView.InvokeRPC(ZNetView.Everybody, "nbusseneau.BetterCartographyTable.RPC_OnPinEvent", new object[2]
			{
				pin.ToCompressedZPackage(),
				(int)pinEvent
			});
			SaveTablePins();
		}

		private void RPC_OnPinEvent(long senderId, ZPackage compressedZPackage, int pinEventInt)
		{
			//IL_0014: 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)
			if ((object)this != CurrentTable)
			{
				return;
			}
			ZDOID zDOID = ((Character)Player.m_localPlayer).GetZDOID();
			long userID = ((ZDOID)(ref zDOID)).UserID;
			if (senderId == userID)
			{
				return;
			}
			SharablePinData pin = compressedZPackage.Decompress().ReadSharablePinData();
			SharablePinData sharablePinData = MinimapManager.SharablePins.SingleOrDefault((SharablePinData p) => pin.Equals((PinData)(object)p));
			if ((object)sharablePinData == null && pinEventInt == 0)
			{
				Minimap.instance.AddPin(pin);
			}
			else if ((object)sharablePinData != null)
			{
				switch (pinEventInt)
				{
				case 1:
					((PinData)(object)sharablePinData).ToggleChecked();
					break;
				case 2:
					Minimap.instance.RemovePin((PinData)(object)sharablePinData);
					break;
				}
			}
			else
			{
				string text = $"Invalid minimap state: cannot handle the received PinEvent given the current minimap data.\npin: {pin} | pinEvent: {(PinEvent)pinEventInt} | isExistingPin: {sharablePinData}";
				Plugin.Logger.LogError((object)text);
			}
		}

		private void SyncVanillaSharedMapData()
		{
			RetrieveExploredMap();
			StoreExploredMapAndPublicPins();
		}

		private void RetrieveExploredMap()
		{
			byte[] byteArray = NView.GetZDO().GetByteArray(ZDOVars.s_data, (byte[])null);
			if (byteArray != null)
			{
				byteArray = Utils.Decompress(byteArray);
				Minimap.instance.AddSharedMapData(byteArray);
			}
		}

		private void StoreExploredMapAndPublicPins()
		{
			byte[] array = NView.GetZDO().GetByteArray(ZDOVars.s_data, (byte[])null);
			if (array != null)
			{
				array = Utils.Decompress(array);
			}
			ZPackage mapData = _mapTable.GetMapData(array);
			NView.InvokeRPC("MapData", new object[1] { mapData });
		}

		public bool Equals(MapTable other)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (other == null)
			{
				return false;
			}
			if (_mapTable == other)
			{
				return true;
			}
			Vector3 position = Position;
			return ((Vector3)(ref position)).Equals(((Component)other).transform.position);
		}

		public override bool Equals(object obj)
		{
			return Equals((MapTable)((obj is MapTable) ? obj : null));
		}

		public static bool operator ==(MapTableManager a, MapTable b)
		{
			if ((object)a != null)
			{
				if (a._mapTable != b)
				{
					return a.Equals(b);
				}
				return true;
			}
			return false;
		}

		public static bool operator !=(MapTableManager a, MapTable b)
		{
			return !(a == b);
		}

		public override int GetHashCode()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = Position;
			return ((object)(Vector3)(ref position)).GetHashCode();
		}
	}
	public static class MinimapManager
	{
		private static List<PinData> AllPins => Minimap.instance.m_pins;

		public static IEnumerable<SharablePinData> SharablePins => AllPins.OfType<SharablePinData>();

		public static IEnumerable<PinData> PrivatePins => AllPins.Where((PinData p) => !(p is SharablePinData)).Concat((IEnumerable<PinData>)SharablePins.Where((SharablePinData p) => p.IsPrivate));

		public static IEnumerable<SharablePinData> SharedPins => SharablePins.Where((SharablePinData p) => p.IsShared);

		public static IEnumerable<SharablePinData> PublicPins
		{
			get
			{
				return SharablePins.Where((SharablePinData p) => p.IsPublic);
			}
			set
			{
				RemovePins(PublicPins);
				AddPins(value);
			}
		}

		public static IEnumerable<SharablePinData> GuildPins
		{
			get
			{
				return SharablePins.Where((SharablePinData p) => p.IsGuild);
			}
			set
			{
				RemovePins(GuildPins);
				AddPins(value);
			}
		}

		public static void AddPins(IEnumerable<SharablePinData> pins)
		{
			pins.ToList().ForEach(delegate(SharablePinData pin)
			{
				Minimap.instance.AddPin(pin);
			});
		}

		public static void RemovePins(IEnumerable<SharablePinData> pins)
		{
			pins.ToList().ForEach(delegate(SharablePinData pin)
			{
				Minimap.instance.RemovePin((PinData)(object)pin);
			});
		}

		public static void HandleClick(ClickType clickType)
		{
			Minimap.instance.HidePinTextInput(false);
			PinData closestPinToMouse = GetClosestPinToMouse();
			if (closestPinToMouse != null)
			{
				if (closestPinToMouse.IsPrivate())
				{
					PrivatePinClickHandler.Dispatch(clickType, closestPinToMouse);
				}
				else if (MapTableManager.IsTableValid && closestPinToMouse is SharablePinData sharablePinData && sharablePinData.SharingMode == MapTableManager.CurrentTable.SharingMode)
				{
					MapTablePinClickHandler.Dispatch(clickType, sharablePinData);
				}
			}
		}

		private static PinData GetClosestPinToMouse()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			Vector3 val = Minimap.instance.ScreenToWorldPoint(Input.mousePosition);
			float num = Minimap.instance.m_removeRadius * (Minimap.instance.m_largeZoom * 2f);
			return Minimap.instance.GetClosestPin(val, num, true);
		}

		public static bool TryConvert(PinData pin, out SharablePinData sharablePin)
		{
			if (((object)pin).GetType() != typeof(PinData))
			{
				sharablePin = null;
				return false;
			}
			sharablePin = new SharablePinData(pin);
			Minimap.instance.RemovePin(pin);
			Minimap.instance.AddPin(sharablePin);
			return true;
		}

		public static void RemoveDuplicateLocalPins()
		{
			((IEnumerable<PinData>)SharedPins).Intersect(PrivatePins).ToList().ForEach((Action<PinData>)Minimap.instance.RemovePin);
		}
	}
}
namespace BetterCartographyTable.Extensions
{
	public static class GameObjectExtensions
	{
		public static void SetText(this GameObject gameObject, string text)
		{
			TextMeshProUGUI componentInChildren = gameObject.GetComponentInChildren<TextMeshProUGUI>();
			string text2 = Localization.instance.Localize(text);
			((TMP_Text)componentInChildren).SetText(text2);
		}
	}
	public static class IEnumerableSharablePinDataExtensions
	{
		public static ZPackage ToCompressedZPackage(this IEnumerable<SharablePinData> pins)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(pins.Count());
			long playerID = Player.m_localPlayer.GetPlayerID();
			string networkUserId = PrivilegeManager.GetNetworkUserId();
			foreach (SharablePinData pin in pins)
			{
				val.Write(pin, playerID, networkUserId);
			}
			return val.Compress();
		}
	}
	public static class KeyCodeExtensions
	{
		public static string ToKeyHintString(this KeyCode keyCode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ZInput.KeyCodeToDisplayName(keyCode);
		}
	}
	public static class MinimapExtensions
	{
		public static SharablePinData AddPin(this Minimap minimap, SharablePinData pin)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return minimap.AddPin(((PinData)pin).m_pos, ((PinData)pin).m_type, ((PinData)pin).m_name, save: true, ((PinData)pin).m_checked, ((PinData)pin).m_ownerID, ((PinData)pin).m_author, pin.SharingMode);
		}

		private static SharablePinData AddPin(this Minimap minimap, Vector3 pos, PinType type, string name, bool save, bool isChecked, long ownerID = 0L, string author = "", SharingMode sharingMode = SharingMode.Private)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			SharablePinData obj = (SharablePinData)(object)minimap.AddPin(pos, type, name, save, isChecked, ownerID, author);
			obj.SharingMode = sharingMode;
			return obj;
		}
	}
	public static class PinDataExtensions
	{
		public static bool IsPrivate(this PinData pin)
		{
			if (!(pin is SharablePinData sharablePinData) || !sharablePinData.IsPrivate)
			{
				return !(pin is SharablePinData);
			}
			return true;
		}

		public static bool IsSharable(this PinData pin)
		{
			return SharablePinData.IsSharable(pin);
		}

		public static void ToggleChecked(this PinData pin)
		{
			pin.m_checked = !pin.m_checked;
			Minimap.instance.m_pinUpdateRequired = true;
		}
	}
	public static class ZPackageExtensions
	{
		public static ZPackage Compress(this ZPackage zPackage)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return new ZPackage(Utils.Compress(zPackage.GetArray()));
		}

		public static ZPackage Decompress(this ZPackage zPackage)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return new ZPackage(Utils.Decompress(zPackage.GetArray()));
		}

		public static SharablePinData ReadSharablePinData(this ZPackage zPackage)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			long ownerID = zPackage.ReadLong();
			string name = zPackage.ReadString();
			Vector3 pos = zPackage.ReadVector3();
			PinType type = (PinType)zPackage.ReadInt();
			bool @checked = zPackage.ReadBool();
			string author = zPackage.ReadString();
			SharingMode sharingMode = (SharingMode)zPackage.ReadInt();
			return new SharablePinData
			{
				m_name = name,
				m_type = type,
				m_pos = pos,
				m_ownerID = ownerID,
				m_author = author,
				m_checked = @checked,
				SharingMode = sharingMode
			};
		}

		public static List<SharablePinData> ReadSharablePinDataList(this ZPackage zPackage)
		{
			List<SharablePinData> list = new List<SharablePinData>();
			int num = zPackage.ReadInt();
			for (int i = 0; i < num; i++)
			{
				SharablePinData item = zPackage.ReadSharablePinData();
				list.Add(item);
			}
			return list;
		}

		public static void Write(this ZPackage zPackage, SharablePinData pin, long currentPlayerID, string networkUserId)
		{
			//IL_0042: 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: Expected I4, but got Unknown
			long num = ((((PinData)pin).m_ownerID != 0L) ? ((PinData)pin).m_ownerID : currentPlayerID);
			string text = ((string.IsNullOrEmpty(((PinData)pin).m_author) && num == currentPlayerID) ? networkUserId : ((PinData)pin).m_author);
			zPackage.Write(num);
			zPackage.Write(((PinData)pin).m_name);
			zPackage.Write(((PinData)pin).m_pos);
			zPackage.Write((int)((PinData)pin).m_type);
			zPackage.Write(((PinData)pin).m_checked);
			zPackage.Write(text);
			zPackage.Write((int)pin.SharingMode);
		}

		public static void Write(this ZPackage zPackage, SharablePinData pin)
		{
			long playerID = Player.m_localPlayer.GetPlayerID();
			string networkUserId = PrivilegeManager.GetNetworkUserId();
			zPackage.Write(pin, playerID, networkUserId);
		}
	}
}
namespace Guilds
{
	[PublicAPI]
	internal static class API
	{
		public delegate void AchievementCompleted(PlayerReference player, string achievment);

		public delegate void GuildJoined(Guild guild, PlayerReference player);

		public delegate void GuildLeft(Guild guild, PlayerReference player);

		public delegate void GuildCreated(Guild guild);

		public delegate void GuildDeleted(Guild guild);

		public static bool IsLoaded()
		{
			return false;
		}

		public static Guild? GetPlayerGuild(PlayerReference player)
		{
			return null;
		}

		public static Guild? GetPlayerGuild(Player player)
		{
			return GetPlayerGuild(PlayerReference.fromPlayer(player));
		}

		public static Guild? GetOwnGuild()
		{
			return GetPlayerGuild(PlayerReference.forOwnPlayer());
		}

		public static Guild? GetGuild(string name)
		{
			return null;
		}

		public static Guild? GetGuild(int id)
		{
			return null;
		}

		public static List<Guild> GetGuilds()
		{
			return new List<Guild>();
		}

		public static PlayerReference GetGuildLeader(Guild guild)
		{
			return guild.Members.FirstOrDefault<KeyValuePair<PlayerReference, GuildMember>>((KeyValuePair<PlayerReference, GuildMember> r) => r.Value.rank == Ranks.Leader).Key;
		}

		public static Guild? CreateGuild(string name, PlayerReference leader)
		{
			return null;
		}

		public static bool DeleteGuild(Guild guild)
		{
			return false;
		}

		public static bool RenameGuild(Guild guild, string newName)
		{
			return true;
		}

		public static bool SaveGuild(Guild guild)
		{
			return false;
		}

		public static bool AddPlayerToGuild(PlayerReference player, Guild guild)
		{
			if (GetPlayerGuild(player) == null)
			{
				guild.Members.Add(player, new GuildMember());
				SaveGuild(guild);
				return true;
			}
			return false;
		}

		public static bool RemovePlayerFromGuild(PlayerReference player)
		{
			Guild playerGuild = GetPlayerGuild(player);
			if (playerGuild != null)
			{
				playerGuild.Members.Remove(player);
				SaveGuild(playerGuild);
				return true;
			}
			return false;
		}

		public static Ranks GetPlayerRank(PlayerReference player)
		{
			return GetPlayerGuild(player)?.Members[player].rank ?? Ranks.Leader;
		}

		public static bool UpdatePlayerRank(PlayerReference player, Ranks newRank)
		{
			Guild playerGuild = GetPlayerGuild(player);
			if (playerGuild != null)
			{
				GuildMember guildMember = playerGuild.Members[player];
				guildMember.rank = newRank;
				playerGuild.Members[player] = guildMember;
				SaveGuild(playerGuild);
				return true;
			}
			return false;
		}

		public static IEnumerable<PlayerReference> GetOnlinePlayers(Guild? guild = null)
		{
			HashSet<PlayerReference> hashSet = new HashSet<PlayerReference>(ZNet.instance.m_players.Select(PlayerReference.fromPlayerInfo));
			if (guild != null)
			{
				return guild.Members.Keys.Where(hashSet.Contains);
			}
			foreach (PlayerReference item in GetGuilds().SelectMany((Guild g) => g.Members.Keys))
			{
				hashSet.Remove(item);
			}
			return hashSet;
		}

		public static Guild? GetOwnAppliedGuild()
		{
			return GetPlayerAppliedGuild(PlayerReference.forOwnPlayer());
		}

		public static Guild? GetPlayerAppliedGuild(PlayerReference player)
		{
			return null;
		}

		public static bool ApplyToGuild(PlayerReference player, string description, Guild guild)
		{
			RemovePlayerApplication(player);
			guild.Applications[player] = new Application
			{
				description = description
			};
			return SaveGuild(guild);
		}

		public static bool RemovePlayerApplication(PlayerReference player, Guild? guild = null)
		{
			Guild playerAppliedGuild = GetPlayerAppliedGuild(player);
			if (playerAppliedGuild != null && (guild == null || playerAppliedGuild == guild))
			{
				playerAppliedGuild.Applications.Remove(player);
				return SaveGuild(playerAppliedGuild);
			}
			return true;
		}

		public static void RegisterCustomData(Type type)
		{
		}

		public static T? GetCustomData<T>(Guild guild) where T : class
		{
			return null;
		}

		public static void SetCustomData<T>(Guild guild, T customData) where T : class
		{
		}

		public static void IncreaseAchievementProgress(Guild guild, string achievement, float increment = 1f)
		{
		}

		public static void RegisterOnAchievementCompleted(AchievementCompleted callback)
		{
		}

		public static void RegisterAchievement(string name, AchievementConfig config)
		{
		}

		internal static AchievementConfig? GetAchievementConfig(string achievement)
		{
			return null;
		}

		internal static IEnumerable<KeyValuePair<string, AchievementConfig>> AllAchievementConfigs()
		{
			return Array.Empty<KeyValuePair<string, AchievementConfig>>();
		}

		public static Sprite? GetGuildIcon(Guild guild)
		{
			return null;
		}

		public static Sprite? GetGuildIconById(int iconId)
		{
			return null;
		}

		public static int GetAchievementStage(Guild guild, AchievementConfig achievement)
		{
			return 0;
		}

		public static void RegisterOnGuildJoined(GuildJoined callback)
		{
		}

		public static void RegisterOnGuildLeft(GuildLeft callback)
		{
		}

		public static void RegisterOnGuildCreated(GuildCreated callback)
		{
		}

		public static void RegisterOnGuildDeleted(GuildDeleted callback)
		{
		}
	}
	[PublicAPI]
	public class Guild
	{
		public string Name = "";

		public GuildGeneral General = new GuildGeneral();

		public Dictionary<PlayerReference, GuildMember> Members = new Dictionary<PlayerReference, GuildMember>();

		public Dictionary<PlayerReference, Application> Applications = new Dictionary<PlayerReference, Application>();

		public Dictionary<string, AchievementData> Achievements = new Dictionary<string, AchievementData>();

		public CustomData customData = new CustomData();
	}
	[PublicAPI]
	public class GuildMember
	{
		public Ranks rank = Ranks.Member;

		public DateTime lastOnline = DateTime.Now;

		public Dictionary<int, Dictionary<string, int>> contribution = new Dictionary<int, Dictionary<string, int>>();
	}
	[PublicAPI]
	public class GuildGeneral
	{
		public int id = 0;

		public string description = "";

		public int icon = 1;

		public int level = 0;

		public string color = "";
	}
	[PublicAPI]
	public class Application
	{
		public DateTime applied = DateTime.Now;

		public string description = "";
	}
	[PublicAPI]
	public class AchievementData
	{
		public float? progress = 0f;

		public List<DateTime> completed = new List<DateTime>();
	}
	[PublicAPI]
	public class CustomData
	{
		internal Dictionary<Type, object> data = new Dictionary<Type, object>();

		internal Dictionary<string, object> unknown = new Dictionary<string, object>();
	}
	[PublicAPI]
	internal class AchievementConfig
	{
		public string name = "";

		public string description = "";

		public List<float> progress = new List<float> { 1f };

		public List<int>? guild = null;

		public List<int> level = new List<int>();

		public string icon = "";

		public bool first;

		public Dictionary<string, string> config = new Dictionary<string, string>();

		public T getConfigValue<T>(string name, T defaultValue = default(T))
		{
			return defaultValue;
		}
	}
	[PublicAPI]
	[TypeConverter(typeof(PlayerReferenceTypeConverter))]
	public struct PlayerReference
	{
		public string id;

		public string name;

		public static PlayerReference fromPlayerInfo(PlayerInfo playerInfo)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			PlayerReference result = default(PlayerReference);
			result.id = (Utility.IsNullOrWhiteSpace(playerInfo.m_host) ? PrivilegeManager.GetNetworkUserId() : (playerInfo.m_host.Contains("_") ? playerInfo.m_host : ("Steam_" + playerInfo.m_host)));
			result.name = playerInfo.m_name ?? "";
			return result;
		}

		public static PlayerReference fromPlayer(Player player)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Player player2 = player;
			return ((Object)(object)player2 == (Object)(object)Player.m_localPlayer) ? forOwnPlayer() : fromPlayerInfo(((IEnumerable<PlayerInfo>)ZNet.instance.m_players).FirstOrDefault((Func<PlayerInfo, bool>)((PlayerInfo info) => info.m_characterID == ((Character)player2).GetZDOID())));
		}

		public static PlayerReference forOwnPlayer()
		{
			PlayerReference result = default(PlayerReference);
			result.id = PrivilegeManager.GetNetworkUserId();
			result.name = Game.instance.GetPlayerProfile().GetName();
			return result;
		}

		public static bool operator !=(PlayerReference a, PlayerReference b)
		{
			return !(a == b);
		}

		public static bool operator ==(PlayerReference a, PlayerReference b)
		{
			return a.id == b.id && a.name == b.name;
		}

		public bool Equals(PlayerReference other)
		{
			return this == other;
		}

		public override bool Equals(object? obj)
		{
			return obj is PlayerReference other && Equals(other);
		}

		public override int GetHashCode()
		{
			return (id.GetHashCode() * 397) ^ name.GetHashCode();
		}

		public override string ToString()
		{
			return id + ":" + name;
		}

		public static PlayerReference fromString(string str)
		{
			string[] array = str.Split(new char[1] { ':' });
			PlayerReference result = default(PlayerReference);
			result.id = array[0];
			result.name = array[1];
			return result;
		}
	}
	internal class PlayerReferenceTypeConverter : TypeConverter
	{
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object? value)
		{
			return PlayerReference.fromString(value?.ToString() ?? ":");
		}
	}
	internal enum Toggle
	{
		On = 1,
		Off = 0
	}
	public enum Ranks
	{
		Leader,
		Coleader,
		Officer,
		Member
	}
}