Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PortalMapMarkers v1.3.0
PortalMapMarkers.dll
Decompiled 5 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.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 PortalMapMarkers { internal sealed class ConfigurationManagerAttributes { public int? Order; public bool? Browsable; public Action<ConfigEntryBase> CustomDrawer; } [BepInPlugin("saymonn.PortalMapMarkers", "PortalMapMarkers", "1.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public enum IconStyle { CustomRing, PortalBuildIcon, StandardPin } [HarmonyPatch(typeof(TextInput), "RequestText")] private static class TextInput_RequestText { [CompilerGenerated] private static class <>O { public static UnityAction <0>__OpenMap; } private static void Postfix(TextInput __instance, TextReceiver sign) { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance.m_panel == (Object)null || !__instance.m_panel.activeSelf) { return; } Transform transform = __instance.m_panel.transform; bool flag = modEnabled.Value && sign is TeleportWorld; Transform val = transform.Find("PMM_MapButton"); if (flag && (Object)(object)val == (Object)null && (Object)(object)InventoryGui.instance != (Object)null) { GameObject gameObject = ((Component)InventoryGui.instance.m_takeAllButton).gameObject; object obj = <>O.<0>__OpenMap; if (obj == null) { UnityAction val2 = OpenMap; <>O.<0>__OpenMap = val2; obj = (object)val2; } GameObject obj2 = MakeButton(gameObject, transform, "PMM_MapButton", "Open World Map", (UnityAction)obj); val = ((obj2 != null) ? obj2.transform : null); Place(val, new Vector2(0.5f, 0f), new Vector2(0.5f, 1f), new Vector2(0f, -12f), new Vector2(260f, 44f)); } if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(flag); } } } [HarmonyPatch(typeof(ZDOMan), "DestroyZDO")] private static class ZDOMan_DestroyZDO { private static void Postfix(ZDO zdo) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (zdo != null && known.ContainsKey(zdo.m_uid)) { pinsDirty = true; } } } [HarmonyPatch(typeof(Piece), "SetCreator")] private static class Piece_SetCreator { private static void Postfix(Piece __instance) { structStale = true; if ((Object)(object)((Component)__instance).GetComponent<TeleportWorld>() != (Object)null) { pinsDirty = true; } } } [HarmonyPatch(typeof(TeleportWorld), "SetText")] private static class TeleportWorld_SetText { private static void Postfix() { pinsDirty = true; } } private class PortalInfo { public Vector3 pos; public Quaternion rot; public float exit; public bool allowAll; public string name; public Sprite icon; } [HarmonyPatch(typeof(Minimap), "UpdatePins")] private static class Minimap_UpdatePins { private static void Postfix() { ApplyLook(); } } [HarmonyPatch(typeof(Minimap), "OnMapLeftClick")] private static class Minimap_OnMapLeftClick { private static void Postfix(Minimap __instance) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (modEnabled.Value && pins.Count != 0 && teleportMode) { ZDOID val = PortalUnderPointer(__instance); if (val != ZDOID.None) { TeleportTo(val); } } } } private sealed class SameZdo : IEqualityComparer<ZDO> { public bool Equals(ZDO a, ZDO b) { return a == b; } public int GetHashCode(ZDO z) { return RuntimeHelpers.GetHashCode(z); } } private sealed class ShipKind { public string label; public Sprite icon; } [HarmonyPatch(typeof(Ship), "Awake")] private static class Ship_Awake { private static void Postfix(Ship __instance) { if (showShips == null || !showShips.Value) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val != null && ZDOMan.instance != null) { ShipKind shipKind = ShipKindOf(val.GetPrefab()); if (shipKind != null && !shipsKnown.ContainsKey(val)) { shipsKnown[val] = shipKind; shipMoveTimer = float.MaxValue; } } } } private class Cell { public int count; public Vector3 sum; public bool seen; } [HarmonyPatch(typeof(ZDOMan), "DestroyZDO")] private static class ZDOMan_DestroyZDO_Structures { private static void Prefix(ZDO zdo) { if (showStructures != null && showStructures.Value && zdo != null && zdo.GetLong(ZDOVars.s_creator, 0L) != 0L) { structStale = true; } } } [CompilerGenerated] private static class <>O { public static Action<ConfigEntryBase> <0>__DrawRgb; public static UnityAction <1>__OpenMap; } private static ConfigEntry<bool> modEnabled; private static ConfigEntry<PinType> pinType; private static ConfigEntry<IconStyle> iconStyle; private static ConfigEntry<Color> markerColor; private static ConfigEntry<Color> labelColor; private static Sprite customSprite; private static IconStyle appliedStyle; private static PinType appliedType; private static ConfigEntry<bool> showUnnamed; private static ConfigEntry<string> unnamedLabel; private static ConfigEntry<bool> showOnNormalMap; private static bool pinsDirty; private static bool teleportMode; private static readonly Dictionary<ZDOID, PortalInfo> known = new Dictionary<ZDOID, PortalInfo>(); private static readonly Dictionary<ZDOID, PinData> pins = new Dictionary<ZDOID, PinData>(); private static Minimap trackedMap; private static readonly FieldInfo pinsField = AccessTools.Field(typeof(Minimap), "m_pins"); private const string MapName = "PMM_MapButton"; private const string MapLabel = "Open World Map"; private static readonly Dictionary<ConfigEntryBase, string> hexText = new Dictionary<ConfigEntryBase, string>(); private static ConfigurationManagerAttributes markerColorTags; private static readonly MethodInfo screenToWorld = AccessTools.Method(typeof(Minimap), "ScreenToWorldPoint", new Type[1] { typeof(Vector3) }, (Type[])null); private static readonly MethodInfo pinRadius = AccessTools.PropertyGetter(typeof(Minimap), "PinInteractRadius"); private static readonly FieldInfo modeField = AccessTools.Field(typeof(Minimap), "m_mode"); private static Texture2D handTex; private static bool handShown; private static ZDOID hoverId = ZDOID.None; private static readonly Vector2 handHotspot = new Vector2(1f, 1f); private static ConfigEntry<bool> showShips; private static ConfigEntry<bool> showStructures; private static ConfigEntry<int> minPieces; private static ConfigEntry<float> baseRadius; private static readonly Dictionary<int, ShipKind> shipKinds = new Dictionary<int, ShipKind>(); private static readonly Dictionary<ZDO, ShipKind> shipsKnown = new Dictionary<ZDO, ShipKind>(new SameZdo()); private static readonly Dictionary<ZDO, PinData> shipPins = new Dictionary<ZDO, PinData>(new SameZdo()); private static readonly List<ZDO> goneShips = new List<ZDO>(); private static readonly FieldRef<ZDOMan, List<ZDO>[]> objectsBySector = AccessTools.FieldRefAccess<ZDOMan, List<ZDO>[]>("m_objectsBySector"); private static bool shipsActive; private static float shipMoveTimer = float.MaxValue; private static float shipSearchTimer = float.MaxValue; private static int scanAt = -1; private static bool firstPass = true; private const float ShipMoveSeconds = 2f; private const float ShipSearchSeconds = 30f; private static readonly List<PinData> structPins = new List<PinData>(); private static readonly Dictionary<int, bool> structPrefabs = new Dictionary<int, bool>(); private static bool structForce; private static bool structStale; private void Awake() { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_01ac: Expected O, but got Unknown //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Expected O, but got Unknown //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Expected O, but got Unknown int order = 10000; modEnabled = Bind("General", "Enabled", value: true, "Master switch. When on, a marker for every portal is always on the map and kept up to date. When off, the markers and the Open World Map button are removed.", ref order); showOnNormalMap = Bind("Markers", "ShowOnNormalMap", value: true, "Also show the portal markers on the normal world map (M). You still cannot teleport from it, only from the Open World Map in the portal window. When off, markers exist only on the custom map.", ref order); iconStyle = Bind("Markers", "IconStyle", IconStyle.CustomRing, "Marker picture: CustomRing = the mod's own wooden portal ring, PortalBuildIcon = the portal's build-menu icon, StandardPin = a normal map pin (see PinIcon).", ref order); markerColorTags = new ConfigurationManagerAttributes { CustomDrawer = DrawRgb }; markerColor = Bind<Color>("Markers", "MarkerColor", Color.white, "Tint of the marker picture (RGB hex). White = the picture as drawn. Shown only for icon styles other than CustomRing.", ref order, markerColorTags); RefreshColorVisibility(); labelColor = Bind<Color>("Markers", "LabelColor", new Color(0.78f, 0.55f, 0.33f, 1f), "Colour of the marker name on the map (RGB hex). Default is a maplewood brown, so it stands out from your own pins.", ref order, new ConfigurationManagerAttributes { CustomDrawer = DrawRgb }); pinType = Bind<PinType>("Markers", "PinIcon", (PinType)3, "Standard map pin icon / category (used by StandardPin, and decides which map filter hides these markers).", ref order); showUnnamed = Bind("Markers", "ShowUnnamedPortals", value: true, "Also mark portals that have no name (tag).", ref order); unnamedLabel = Bind("Markers", "UnnamedLabel", "Portal", "Label shown for portals without a name.", ref order); BindExtras(ref order); ((BaseUnityPlugin)this).Config.SettingChanged += delegate { //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) structForce = true; RefreshColorVisibility(); if (!showOnNormalMap.Value && !teleportMode) { RemoveAll(message: false); } else { if (pins.Count > 0 && (iconStyle.Value != appliedStyle || pinType.Value != appliedType)) { RemoveAll(message: false); } pinsDirty = true; } }; Harmony val = new Harmony("saymonn.PortalMapMarkers"); val.PatchAll(); Type type = AccessTools.TypeByName("XPortal.UI.PortalConfigurationPanel"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Show", (Type[])null, (Type[])null)); if (methodInfo != null) { val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "XPortalShown", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else if (type != null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"XPortal found but its window method changed; buttons will not appear there."); } MethodInfo methodInfo2 = ((type == null) ? null : AccessTools.Method(type, "Hide", (Type[])null, (Type[])null)); if (methodInfo2 != null) { val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "XPortalHidden", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void XPortalShown() { //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_0087: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value) { return; } GameObject val = GameObject.Find("_GameMain/LoadingGUI/CustomGUIFront/XPortal_MainPanel"); if ((Object)(object)val == (Object)null || (Object)(object)val.transform.Find("PMM_MapButton") != (Object)null) { return; } Transform val2 = val.transform.Find("XPortal_CancelButton"); if (!((Object)(object)val2 == (Object)null)) { GameObject gameObject = ((Component)val2).gameObject; Transform transform = val.transform; object obj = <>O.<1>__OpenMap; if (obj == null) { UnityAction val3 = OpenMap; <>O.<1>__OpenMap = val3; obj = (object)val3; } GameObject val4 = MakeButton(gameObject, transform, "PMM_MapButton", "Open World Map", (UnityAction)obj); Place(((Object)(object)val4 == (Object)null) ? null : val4.transform, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(24f, 24f), new Vector2(260f, 48f)); } } private static void Place(Transform t, Vector2 anchor, Vector2 pivot, Vector2 pos, Vector2 size) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)t == (Object)null)) { Transform obj = ((t is RectTransform) ? t : null); ((RectTransform)obj).anchorMin = anchor; ((RectTransform)obj).anchorMax = anchor; ((RectTransform)obj).pivot = pivot; ((RectTransform)obj).anchoredPosition = pos; ((RectTransform)obj).sizeDelta = size; } } private static GameObject MakeButton(GameObject template, Transform parent, string name, string label, UnityAction click) { //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Expected O, but got Unknown if ((Object)(object)template == (Object)null) { return null; } GameObject val = Object.Instantiate<GameObject>(template, parent, false); ((Object)val).name = name; val.SetActive(true); UIGamePad[] componentsInChildren = val.GetComponentsInChildren<UIGamePad>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.Destroy((Object)(object)componentsInChildren[i]); } UIInputHint[] componentsInChildren2 = val.GetComponentsInChildren<UIInputHint>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.Destroy((Object)(object)componentsInChildren2[i]); } Localize[] componentsInChildren3 = val.GetComponentsInChildren<Localize>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.Destroy((Object)(object)componentsInChildren3[i]); } Transform[] componentsInChildren4 = val.GetComponentsInChildren<Transform>(true); foreach (Transform val2 in componentsInChildren4) { if ((Object)(object)val2 != (Object)(object)val.transform && ((Object)val2).name.ToLowerInvariant().Contains("hint")) { ((Component)val2).gameObject.SetActive(false); } } Text[] componentsInChildren5 = val.GetComponentsInChildren<Text>(true); for (int i = 0; i < componentsInChildren5.Length; i++) { componentsInChildren5[i].text = label; } TMP_Text[] componentsInChildren6 = val.GetComponentsInChildren<TMP_Text>(true); for (int i = 0; i < componentsInChildren6.Length; i++) { componentsInChildren6[i].text = label; } Button component = val.GetComponent<Button>(); if ((Object)(object)component != (Object)null) { component.onClick = new ButtonClickedEvent(); ((UnityEvent)component.onClick).AddListener(click); } return val; } private ConfigEntry<T> Bind<T>(string section, string key, T value, string description, ref int order, ConfigurationManagerAttributes tags = null) { //IL_002c: 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_004a: Expected O, but got Unknown //IL_004a: Expected O, but got Unknown tags = tags ?? new ConfigurationManagerAttributes(); tags.Order = order--; return ((BaseUnityPlugin)this).Config.Bind<T>(new ConfigDefinition(section, key), value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { tags })); } private static Color Opaque(Color c) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) c.a = 1f; return c; } private static void DrawRgb(ConfigEntryBase entry) { //IL_0008: 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) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) ConfigEntry<Color> val = (ConfigEntry<Color>)(object)entry; Color val2 = Opaque(val.Value); if (!hexText.TryGetValue(entry, out var value)) { value = ColorUtility.ToHtmlStringRGB(val2); } GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); Color color = GUI.color; GUI.color = val2; GUILayout.Label((Texture)(object)Texture2D.whiteTexture, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(40f), GUILayout.Height(20f) }); GUI.color = color; string text = GUILayout.TextField(value, 6, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }); GUILayout.Label("RRGGBB", Array.Empty<GUILayoutOption>()); GUILayout.EndHorizontal(); if (text != value) { hexText[entry] = text; Color c = default(Color); if (text.Length == 6 && ColorUtility.TryParseHtmlString("#" + text, ref c)) { val.Value = Opaque(c); } } } private static void RefreshColorVisibility() { if (markerColorTags != null) { markerColorTags.Browsable = iconStyle.Value != IconStyle.CustomRing; } } private void Update() { UpdateCursor(); ApplyLook(); if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Minimap.instance == (Object)null) { return; } if ((Object)(object)trackedMap != (Object)(object)Minimap.instance) { trackedMap = Minimap.instance; pins.Clear(); pinsDirty = true; ResetExtras(); } if (!modEnabled.Value) { if (pins.Count > 0) { RemoveAll(message: false); } ClearExtras(); teleportMode = false; return; } if (teleportMode && !Minimap.IsOpen()) { teleportMode = false; if (!showOnNormalMap.Value) { RemoveAll(message: false); } } if (pinsDirty) { pinsDirty = false; if (showOnNormalMap.Value || teleportMode) { AddAll(message: false); } } UpdateExtras(Time.unscaledDeltaTime); } private static void XPortalHidden() { pinsDirty = true; } private static Dictionary<ZDOID, PortalInfo> FindPortals() { //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) Dictionary<ZDOID, PortalInfo> dictionary = new Dictionary<ZDOID, PortalInfo>(); if ((Object)(object)ZNetScene.instance == (Object)null || ZDOMan.instance == null) { return dictionary; } foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab == (Object)null || (Object)(object)prefab.GetComponent<TeleportWorld>() == (Object)null) { continue; } Sprite icon = prefab.GetComponent<Piece>()?.m_icon; List<ZDO> list = new List<ZDO>(); int num = 0; int num2 = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(((Object)prefab).name, list, ref num) && num2++ < 100000) { } foreach (ZDO item in list) { if (item != null && item.IsValid()) { dictionary[item.m_uid] = new PortalInfo { pos = item.GetPosition(), rot = item.GetRotation(), exit = prefab.GetComponent<TeleportWorld>().m_exitDistance, allowAll = prefab.GetComponent<TeleportWorld>().m_allowAllItems, name = item.GetString("tag", ""), icon = icon }; } } } return dictionary; } private static Sprite WantedIcon(PortalInfo p) { return (Sprite)(iconStyle.Value switch { IconStyle.CustomRing => GetCustomSprite(), IconStyle.PortalBuildIcon => p.icon, _ => null, }); } private static Sprite GetCustomSprite() { //IL_0041: 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) if ((Object)(object)customSprite != (Object)null) { return customSprite; } Texture2D val = LoadTexture("PortalMapMarkers.portal_pin.png", mipmaps: true); if ((Object)(object)val != (Object)null) { customSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); } return customSprite; } private static void ApplyLook() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) if (pins.Count == 0) { return; } foreach (KeyValuePair<ZDOID, PinData> pin in pins) { PinData value = pin.Value; bool flag = pin.Key == hoverId; if ((Object)(object)value.m_iconElement != (Object)null) { Color val = Opaque(markerColor.Value); ((Graphic)value.m_iconElement).color = (flag ? Color.Lerp(val, Color.white, 0.6f) : val); ((Transform)value.m_uiElement).localScale = (Vector3)(flag ? new Vector3(1.35f, 1.35f, 1f) : Vector3.one); } PinNameData namePinData = value.m_NamePinData; TMP_Text val2 = ((namePinData != null) ? namePinData.PinNameText : null); if ((Object)(object)val2 != (Object)null) { Color val3 = Opaque(labelColor.Value); ((Graphic)val2).color = (flag ? Color.Lerp(val3, Color.black, 0.3f) : val3); } } } private static void OpenMap() { if (!((Object)(object)Minimap.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null)) { AddAll(message: false); CloseWindows(); teleportMode = true; Minimap.instance.SetMapMode((MapMode)2); Say("Click a portal marker to teleport there."); } } private static void CloseWindows() { if ((Object)(object)TextInput.instance != (Object)null && (Object)(object)TextInput.instance.m_panel != (Object)null && TextInput.instance.m_panel.activeSelf) { TextInput.instance.Hide(); } Type type = AccessTools.TypeByName("XPortal.UI.PortalConfigurationPanel"); if (!(type == null)) { object obj = AccessTools.Property(type, "Instance")?.GetValue(null, null); MethodInfo methodInfo = AccessTools.Method(type, "Hide", (Type[])null, (Type[])null); if (obj != null && methodInfo != null) { methodInfo.Invoke(obj, new object[2] { false, null }); } } } private static ZDOID PortalUnderPointer(Minimap map) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (Vector3)screenToWorld.Invoke(map, new object[1] { ZInput.pointerPosition }); float num = (float)pinRadius.Invoke(map, null); ZDOID result = ZDOID.None; float num2 = num; foreach (KeyValuePair<ZDOID, PinData> pin in pins) { PinData value = pin.Value; if (!((Object)(object)value.m_uiElement == (Object)null) && ((Component)value.m_uiElement).gameObject.activeInHierarchy) { float num3 = Utils.DistanceXZ(val, value.m_pos); if (num3 < num2) { num2 = num3; result = pin.Key; } } } return result; } private static void UpdateCursor() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) bool flag = false; hoverId = ZDOID.None; Minimap instance = Minimap.instance; if (modEnabled.Value && (Object)(object)instance != (Object)null && pins.Count > 0 && (Object)(object)Player.m_localPlayer != (Object)null && (int)modeField.GetValue(instance) == 2 && teleportMode) { hoverId = PortalUnderPointer(instance); flag = hoverId != ZDOID.None; } if (flag == handShown) { return; } if (flag) { if ((Object)(object)handTex == (Object)null) { handTex = LoadTexture("PortalMapMarkers.cursor_dagger.png", mipmaps: false); } if ((Object)(object)handTex == (Object)null) { return; } Cursor.SetCursor(handTex, handHotspot, (CursorMode)0); } else { Cursor.SetCursor((Texture2D)null, Vector2.zero, (CursorMode)0); } handShown = flag; } private void OnDisable() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (handShown) { Cursor.SetCursor((Texture2D)null, Vector2.zero, (CursorMode)0); handShown = false; } } private static Texture2D LoadTexture(string resource, bool mipmaps) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown try { using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(resource); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, mipmaps); if (!ImageConversion.LoadImage(val, array)) { return null; } ((Texture)val).filterMode = (FilterMode)1; return val; } catch (Exception ex) { Debug.LogWarning((object)("[PortalMapMarkers] could not load " + resource + ": " + ex.Message)); return null; } } private static void TeleportTo(ZDOID id) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0059: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !known.TryGetValue(id, out var value)) { return; } if (!((Humanoid)localPlayer).IsTeleportable(value.allowAll)) { ((Character)localPlayer).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false); return; } Vector3 val = value.pos + value.rot * Vector3.forward * value.exit + Vector3.up; ((Character)localPlayer).TeleportTo(val, value.rot, true); teleportMode = false; if (!showOnNormalMap.Value) { RemoveAll(message: false); } if ((Object)(object)Minimap.instance != (Object)null) { Minimap.instance.SetMapMode((MapMode)1); } UpdateCursor(); } private static bool OnMap(PinData pin) { if (pinsField.GetValue(Minimap.instance) is List<PinData> list) { return list.Contains(pin); } return false; } private static void AddAll(bool message) { //IL_0042: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value || (Object)(object)Minimap.instance == (Object)null) { return; } Dictionary<ZDOID, PortalInfo> dictionary = FindPortals(); known.Clear(); foreach (KeyValuePair<ZDOID, PortalInfo> item in dictionary) { known[item.Key] = item.Value; } foreach (ZDOID item2 in new List<ZDOID>(pins.Keys)) { if (!dictionary.ContainsKey(item2) || !OnMap(pins[item2]) || (!showUnnamed.Value && string.IsNullOrEmpty(dictionary[item2].name))) { if (OnMap(pins[item2])) { Minimap.instance.RemovePin(pins[item2]); } pins.Remove(item2); } } appliedStyle = iconStyle.Value; appliedType = pinType.Value; int num = 0; foreach (KeyValuePair<ZDOID, PortalInfo> item3 in dictionary) { PortalInfo value = item3.Value; if (string.IsNullOrEmpty(value.name) && !showUnnamed.Value) { continue; } string text = (string.IsNullOrEmpty(value.name) ? unnamedLabel.Value : value.name); if (pins.TryGetValue(item3.Key, out var value2)) { Sprite val = WantedIcon(value); if (value2.m_name == text && value2.m_pos == value.pos && value2.m_type == pinType.Value && ((Object)(object)val == (Object)null || (Object)(object)value2.m_icon == (Object)(object)val)) { continue; } Minimap.instance.RemovePin(value2); pins.Remove(item3.Key); } PinData val2 = Minimap.instance.AddPin(value.pos, pinType.Value, text, false, false, 0L, default(PlatformUserID)); if (val2 != null) { Sprite val3 = WantedIcon(value); if ((Object)(object)val3 != (Object)null) { val2.m_icon = val3; } pins[item3.Key] = val2; num++; } } if (message) { Say($"Portal markers: {pins.Count} on the map ({num} new)."); } } private static void RemoveAll(bool message) { int num = 0; if ((Object)(object)Minimap.instance != (Object)null) { foreach (PinData value in pins.Values) { if (OnMap(value)) { Minimap.instance.RemovePin(value); num++; } } } pins.Clear(); if (message) { Say($"Portal markers removed: {num}."); } } private static void Say(string text) { if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)1, text, 0, (Sprite)null, false); } } private void BindExtras(ref int order) { showShips = Bind("Ships", "ShowShips", value: true, "Show the location of every ship in the world (moored or sailing, vanilla and modded) on the map. Works on the normal map and on the custom map.", ref order); showStructures = Bind("Structures", "ShowStructures", value: false, "Show every base you ever built on the map (one marker per base, with the number of pieces). Works on the normal map and on the custom map. Useful for houses without a portal.", ref order); minPieces = Bind("Structures", "MinPiecesPerBase", 10, "A group of your buildings needs at least this many pieces to get a marker (so a lone torch or workbench does not).", ref order); baseRadius = Bind("Structures", "BaseRadius", 40f, "Buildings closer together than about this many metres are treated as one base.", ref order); } private static void UpdateExtras(float dt) { if (showShips.Value) { if (!shipsActive) { shipsActive = true; shipMoveTimer = float.MaxValue; shipSearchTimer = float.MaxValue; } UpdateShips(dt); } else if (shipsActive || shipPins.Count > 0) { shipsActive = false; ClearShips(); } if (!showStructures.Value) { if (structPins.Count > 0) { ClearStructures(); } structForce = false; } else if (structForce || (structStale && Minimap.IsOpen())) { structForce = false; structStale = false; RescanStructures(); } } private static void ClearExtras() { ClearShips(); ClearStructures(); shipsActive = false; } private static void ResetExtras() { shipPins.Clear(); structPins.Clear(); shipsKnown.Clear(); shipsActive = false; scanAt = -1; firstPass = true; shipMoveTimer = float.MaxValue; shipSearchTimer = float.MaxValue; structForce = true; } private static void UpdateShips(float dt) { ZDOMan instance = ZDOMan.instance; if (instance != null && !((Object)(object)ZNetScene.instance == (Object)null)) { shipSearchTimer += dt; if (scanAt < 0 && shipSearchTimer >= 30f) { shipSearchTimer = 0f; scanAt = 0; } if (scanAt >= 0) { SearchShips(instance); } shipMoveTimer += dt; if (shipMoveTimer >= 2f) { shipMoveTimer = 0f; MoveShips(); } } } private static void SearchShips(ZDOMan zm) { List<ZDO>[] array = objectsBySector.Invoke(zm); int num = (firstPass ? 20000 : 2000); while (scanAt < array.Length && num > 0) { List<ZDO> list = array[scanAt++]; num--; if (list == null) { continue; } num -= list.Count; foreach (ZDO item in list) { ShipKind shipKind = ShipKindOf(item.GetPrefab()); if (shipKind != null && !shipsKnown.ContainsKey(item)) { shipsKnown[item] = shipKind; } } } if (scanAt >= array.Length) { scanAt = -1; firstPass = false; shipMoveTimer = float.MaxValue; } } private static void MoveShips() { Player localPlayer = Player.m_localPlayer; Ship steered = (((Object)(object)localPlayer == (Object)null) ? null : localPlayer.GetControlledShip()); goneShips.Clear(); foreach (KeyValuePair<ZDO, ShipKind> item in shipsKnown) { if (!item.Key.IsValid() || ShipKindOf(item.Key.GetPrefab()) != item.Value) { goneShips.Add(item.Key); } else { PinShip(steered, item.Key, item.Value); } } foreach (ZDO goneShip in goneShips) { shipsKnown.Remove(goneShip); if (shipPins.TryGetValue(goneShip, out var value)) { Minimap.instance.RemovePin(value); shipPins.Remove(goneShip); } } } private static void PinShip(Ship steered, ZDO zdo, ShipKind kind) { //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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null) { return; } Vector3 position = zdo.GetPosition(); PinData value; bool flag = shipPins.TryGetValue(zdo, out value); if ((Object)(object)steered != (Object)null && Vector3.Distance(((Component)steered).transform.position, position) < 0.01f) { if (flag) { instance.RemovePin(value); shipPins.Remove(zdo); } return; } if (flag) { value.m_pos = position; return; } value = instance.AddPin(position, (PinType)6, kind.label, false, false, 0L, default(PlatformUserID)); if (value != null) { if ((Object)(object)kind.icon != (Object)null) { value.m_icon = kind.icon; } value.m_doubleSize = true; shipPins[zdo] = value; } } private static ShipKind ShipKindOf(int hash) { if (shipKinds.TryGetValue(hash, out var value)) { return value; } if ((Object)(object)ZNetScene.instance == (Object)null) { return null; } GameObject prefab = ZNetScene.instance.GetPrefab(hash); if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<Ship>() != (Object)null) { Piece component = prefab.GetComponent<Piece>(); string label = (((Object)(object)component != (Object)null && !string.IsNullOrEmpty(component.m_name)) ? Localization.instance.Localize(component.m_name) : ((Object)prefab).name); value = new ShipKind { label = label, icon = (((Object)(object)component != (Object)null) ? component.m_icon : null) }; } shipKinds[hash] = value; return value; } private static void ClearShips() { if ((Object)(object)Minimap.instance != (Object)null) { foreach (PinData value in shipPins.Values) { Minimap.instance.RemovePin(value); } } shipPins.Clear(); } private static long CellKey(int cx, int cz) { return ((long)cx << 32) | (uint)cz; } private static bool IsStructurePrefab(int hash) { if (structPrefabs.TryGetValue(hash, out var value)) { return value; } if ((Object)(object)ZNetScene.instance == (Object)null) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab(hash); value = (Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<Piece>() != (Object)null && (Object)(object)prefab.GetComponent<Ship>() == (Object)null && (Object)(object)prefab.GetComponent<Vagon>() == (Object)null && (Object)(object)prefab.GetComponent<Plant>() == (Object)null; structPrefabs[hash] = value; return value; } private static void RescanStructures() { //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: 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_00ab: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) ClearStructures(); ZDOMan instance = ZDOMan.instance; if (instance == null || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)Minimap.instance == (Object)null) { return; } float num = Mathf.Max(10f, baseRadius.Value); Dictionary<long, Cell> dictionary = new Dictionary<long, Cell>(); List<ZDO>[] array = objectsBySector.Invoke(instance); foreach (List<ZDO> list in array) { if (list == null) { continue; } foreach (ZDO item in list) { if (item != null && item.GetLong(ZDOVars.s_creator, 0L) != 0L && IsStructurePrefab(item.GetPrefab())) { Vector3 position = item.GetPosition(); long key = CellKey(Mathf.FloorToInt(position.x / num), Mathf.FloorToInt(position.z / num)); if (!dictionary.TryGetValue(key, out var value)) { value = (dictionary[key] = new Cell()); } value.count++; Cell cell2 = value; cell2.sum += position; } } } int num2 = 0; foreach (long item2 in new List<long>(dictionary.Keys)) { if (dictionary[item2].seen) { continue; } int num3 = 0; Vector3 val = Vector3.zero; Queue<long> queue = new Queue<long>(); dictionary[item2].seen = true; queue.Enqueue(item2); while (queue.Count > 0) { long num4 = queue.Dequeue(); Cell cell3 = dictionary[num4]; num3 += cell3.count; val += cell3.sum; int num5 = (int)(num4 >> 32); int num6 = (int)(num4 & 0xFFFFFFFFu); for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { if ((j != 0 || k != 0) && dictionary.TryGetValue(CellKey(num5 + j, num6 + k), out var value2) && !value2.seen) { value2.seen = true; queue.Enqueue(CellKey(num5 + j, num6 + k)); } } } } if (num3 >= minPieces.Value) { PinData val2 = Minimap.instance.AddPin(val / (float)num3, (PinType)1, "Base (" + num3 + ")", false, false, 0L, default(PlatformUserID)); if (val2 != null) { structPins.Add(val2); num2++; } } } } private static void ClearStructures() { if ((Object)(object)Minimap.instance != (Object)null) { foreach (PinData structPin in structPins) { Minimap.instance.RemovePin(structPin); } } structPins.Clear(); } } }