using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using GUIFramework; using HarmonyLib; using JetBrains.Annotations; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using Zen; using Zen.Interop; using Zen.Lib; using Zen.Lib.Config; using Zen.Lib.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ZenMap")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ZenMap")] [assembly: AssemblyCopyright("Copyright \ufffd 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] [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 ZenMap { internal static class ColorExt { public static uint ToUInt(this Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) return Color32.op_Implicit(color).ToUInt(); } public static uint ToUInt(this Color32 color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) return (uint)((color.r << 24) | (color.g << 16) | (color.b << 8) | color.a); } public static Color ToColor(this uint rgba) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) return Color32.op_Implicit(new Color32((byte)(rgba >> 24), (byte)(rgba >> 16), (byte)(rgba >> 8), (byte)rgba)); } } internal static class DataKey { public const int CurrentVersion = 1; public const string MapID = "ZenMap_id"; public const string Seed = "ZenMap_seed"; public const string Label = "ZenMap_label"; public const string Position = "ZenMap_position"; public const string Radius = "ZenMap_radius"; public const string Pins = "ZenMap_pins"; public const string Timestamp = "ZenMap_timestamp"; public const string Version = "ZenMap_version"; public const string LastUsedMapID = "ZenMap_LastUsedMapID"; } [HarmonyPatch] internal static class FireplaceUtils { [HarmonyPostfix] [HarmonyPatch(typeof(Fireplace), "Interact")] private static void Fireplace_Interact(Fireplace __instance) { if (StringExtensionMethods.GetStableHashCode(GameObjectExt.GetPrefabName(((Component)__instance).gameObject)) == MapTrack.Pin.Bonfire) { Minimap.instance.m_pinUpdateRequired = true; } } public static bool IsLit(ZDO zdo) { Fireplace prefab = GlobalStatic.GetPrefab(ZdoExt.GetPrefabName(zdo), true); if (prefab.m_infiniteFuel) { return true; } if (prefab.m_secPerFuel <= 0f) { return false; } float @float = zdo.GetFloat(ZDOVars.s_fuel, 0f); DateTime time = ZNet.instance.GetTime(); DateTime dateTime = new DateTime(zdo.GetLong(ZDOVars.s_lastTime, time.Ticks)); double num = Math.Max(0.0, (time - dateTime).TotalSeconds) / (double)prefab.m_secPerFuel; return (double)@float - num > 0.0; } } [HarmonyPatch] internal static class InventoryCheck { private static bool _isFound; public static bool HaveMap { get; private set; } internal static void Init() { HaveMap = InventoryExt.ContainsItemByPrefab(((Humanoid)Player.m_localPlayer).GetInventory(), "ZenMap"); _isFound = false; } private static bool IsValid(Inventory inv) { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return inv == ((Humanoid)Player.m_localPlayer).GetInventory(); } return false; } private static void Reset(Inventory inv) { if (IsValid(inv)) { _isFound = false; } } private static void CheckIfHadMap(Inventory inv) { if (IsValid(inv) && Object.op_Implicit((Object)(object)Minimap.instance) && Minimap.instance.m_visibleIconTypes == MapPinType.VisibleTypes.CompassWithMap && !_isFound) { RequirePinUpdate(); } } private static void CheckMapItem(Inventory inv, ItemData item) { if (IsValid(inv) && !_isFound) { HaveMap = ItemDataExt.GetPrefabName(item) == "ZenMap"; if (HaveMap) { _isFound = true; RequirePinUpdate(); } } } private static void RequirePinUpdate() { if (Object.op_Implicit((Object)(object)Minimap.instance)) { Minimap.instance.m_pinUpdateRequired = true; } } [HarmonyPrefix] [HarmonyPatch(typeof(Player), "OnSpawned")] private static void Player_OnSpawned() { Init(); } [HarmonyTranspiler] [HarmonyPatch(typeof(Inventory), "UpdateTotalWeight")] private static IEnumerable Inventory_UpdateTotalWeight_Transpiler(IEnumerable codes) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Expected O, but got Unknown //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown //IL_014b: Unknown result type (might be due to invalid IL or missing references) CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(ItemData), "GetWeight", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(Inventory), "m_totalWeight"), (string)null) }; Action action = Reset; CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)action.Method) }; Action action2 = CheckMapItem; CodeInstruction[] array3 = (CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldloc_1, (object)null), new CodeInstruction(OpCodes.Call, (object)action2.Method) }; Action action3 = CheckIfHadMap; CodeInstruction[] array4 = (CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)action3.Method) }; return new CodeMatcher(codes, (ILGenerator)null).Start().Insert(array2).MatchEndForward(array) .ThrowIfInvalid("Unable to match IL") .Advance(1) .Insert(array3) .End() .Insert(array4) .InstructionEnumeration(); } } [HarmonyPatch] internal static class MapClouds { private static Texture2D? _cloudsCache; private static readonly Texture2D NoClouds; private static bool _isVisible; private static readonly int CloudTexID; static MapClouds() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) _isVisible = true; CloudTexID = Shader.PropertyToID("_CloudTex"); NoClouds = new Texture2D(1, 1); NoClouds.SetPixel(0, 0, Color.clear); NoClouds.Apply(); } public static void ResetState() { if (Object.op_Implicit((Object)(object)Minimap.instance) && Object.op_Implicit((Object)(object)_cloudsCache)) { Minimap.instance.m_mapLargeShader.SetTexture(CloudTexID, (Texture)(object)_cloudsCache); } _isVisible = true; _cloudsCache = null; } internal static void Shutdown() { if (Object.op_Implicit((Object)(object)_cloudsCache) && Object.op_Implicit((Object)(object)Minimap.instance)) { Minimap.instance.m_mapLargeShader.SetTexture(CloudTexID, (Texture)(object)_cloudsCache); } } [HarmonyPostfix] [HarmonyPatch(typeof(Minimap), "Start")] private static void Minimap_Start() { ResetState(); } [HarmonyPrefix] [HarmonyPatch(typeof(Minimap), "UpdateMap")] private static void Minimap_UpdateMap(Minimap __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) if ((int)__instance.m_mode != 2) { return; } Material mapLargeShader = __instance.m_mapLargeShader; if (!Object.op_Implicit((Object)(object)_cloudsCache)) { _cloudsCache = (Texture2D)mapLargeShader.GetTexture(CloudTexID); } if ((Configs.HideMapItemClouds.Value && MapLocation.IsMapItem()) || (Configs.HideMapTableClouds.Value && MapLocation.IsMapTable())) { if (_isVisible) { mapLargeShader.SetTexture(CloudTexID, (Texture)(object)NoClouds); _isVisible = false; } return; } bool flag = ZInput.GetKey(Configs.InputHideMapCloudsKey.Value, true) || ZInput.GetButton("JoyRStick"); if (flag == _isVisible) { _isVisible = !flag; mapLargeShader.SetTexture(CloudTexID, (Texture)(_isVisible ? ((object)_cloudsCache) : ((object)NoClouds))); } } } [HarmonyPatch] internal static class MapFog { private static Texture2D? _fogAll; private static Texture2D? _fogNone; private static bool[] _exploreAll = Array.Empty(); private static bool _isInit; private const int PrioritySuperLast = -1000; [HarmonyPostfix] [HarmonyPatch(typeof(Minimap), "Start")] [HarmonyPriority(-1000)] private static void Minimap_Start(Minimap __instance) { InitFogCache(); } [HarmonyPostfix] [HarmonyPatch(typeof(Minimap), "OnDestroy")] private static void Minimap_OnDestroy() { RemoveFogCache(); } [HarmonyPrefix] [HarmonyPatch(typeof(Minimap), "ExploreAll")] private static void Minimap_ExploreAll(ref bool __runOriginal) { if (_isInit) { __runOriginal = false; FastExploreAll(); } } [HarmonyPrefix] [HarmonyPatch(typeof(Minimap), "Reset")] private static void Minimap_Reset(ref bool __runOriginal) { if (_isInit) { __runOriginal = false; FastReset(); Minimap.instance.m_sharedMapHint.gameObject.SetActive(false); } } private static bool IsValidMinimap() { if (Object.op_Implicit((Object)(object)Minimap.instance) && Object.op_Implicit((Object)(object)Minimap.instance.m_fogTexture) && Minimap.instance.m_explored != null && Minimap.instance.m_explored.Length != 0) { return true; } Logging.Error((object)"Minimap instance is not valid", (ushort)0); return false; } private static bool ValidateFogCache() { if (Configs.DisableFogCache.Value) { return false; } if (!IsValidMinimap()) { return false; } int width = ((Texture)Minimap.instance.m_fogTexture).width; int height = ((Texture)Minimap.instance.m_fogTexture).height; int num = Minimap.instance.m_explored.Length; int num2 = (Object.op_Implicit((Object)(object)_fogAll) ? ((Texture)_fogAll).width : 0); int num3 = (Object.op_Implicit((Object)(object)_fogAll) ? ((Texture)_fogAll).height : 0); int num4 = _exploreAll.Length; if (width == num2 && height == num3 && num == num4 && IsFogCacheTexturesSizesEqual()) { Logging.Info((object)"Fog cache sizes OK", 0); return true; } Logging.Warning((object)$"Map: {width}x{height} Cache: {num2}x{num3}, MapExplored: {num}, CacheExplored: {num4}", 0); Logging.Warning((object)"Fog cache is missing or invalid. Reinitializing...", 0); return InitFogCache(); static bool IsFogCacheTexturesSizesEqual() { if (Object.op_Implicit((Object)(object)_fogAll) && Object.op_Implicit((Object)(object)_fogNone) && ((Texture)_fogNone).width == ((Texture)_fogAll).width) { return ((Texture)_fogNone).height == ((Texture)_fogAll).height; } return false; } } internal static void RemoveFogCache() { Logging.Info((object)"Remove existing fog cache", 0); if (Object.op_Implicit((Object)(object)_fogAll)) { Object.Destroy((Object)(object)_fogAll); } if (Object.op_Implicit((Object)(object)_fogNone)) { Object.Destroy((Object)(object)_fogNone); } _fogAll = null; _fogNone = null; _exploreAll = Array.Empty(); _isInit = false; } private static void InitFog(this Texture2D texture, Color32 color) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[((Texture)texture).width * ((Texture)texture).height]; for (int i = 0; i < array.Length; i++) { array[i] = color; } texture.SetPixels32(array); texture.Apply(); } internal static bool InitFogCache() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) _isInit = false; if (Configs.DisableFogCache.Value) { Logging.Warning((object)"Fog cache is disabled", 0); return false; } if (!IsValidMinimap()) { return false; } Logging.Info((object)"Initialize the fog cache", 0); if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsDedicated()) { Logging.Info((object)"Dedicated server, no UI, aborting fog cache creation", 0); return false; } RemoveFogCache(); _fogAll = Create(Minimap.instance.m_fogTexture, "All"); _fogNone = Create(Minimap.instance.m_fogTexture, "None"); _fogAll.InitFog(Color32.op_Implicit(Color.white)); _fogNone.InitFog(Color32.op_Implicit(Color.clear)); Logging.Info((object)$"ExploreAll array size m_explored: {Minimap.instance.m_explored.Length}", 0); _exploreAll = Enumerable.Repeat(element: true, Minimap.instance.m_explored.Length).ToArray(); return _isInit = true; static Texture2D Create(Texture2D tex, string name) { //IL_0034: 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_0047: Expected O, but got Unknown Logging.Info((object)$"Initialize texture {name} size {((Texture)tex).width}x{((Texture)tex).height}", 0); return new Texture2D(((Texture)tex).width, ((Texture)tex).height, tex.format, ((Texture)tex).mipmapCount, false, true); } } private static void FastExploreAll() { if (ValidateFogCache()) { Logging.Info((object)"Set the fog texture to no fog", 0); Graphics.CopyTexture((Texture)(object)_fogNone, (Texture)(object)Minimap.instance.m_fogTexture); Minimap.instance.m_fogTexture.Apply(); Logging.Info((object)"Set the explored area to all", 0); _exploreAll.CopyTo(Minimap.instance.m_explored, 0); } } private static void FastReset() { if (ValidateFogCache()) { Logging.Info((object)"Set the fog texture to all fog", 0); Graphics.CopyTexture((Texture)(object)_fogAll, (Texture)(object)Minimap.instance.m_fogTexture); Minimap.instance.m_fogTexture.Apply(); Logging.Info((object)"Reset the explored area to none", 0); ArrayClear(Minimap.instance.m_explored); ArrayClear(Minimap.instance.m_exploredOthers); } static void ArrayClear(Array? ar) { if (ar != null) { Array.Clear(ar, 0, ar.Length); } } } } [HarmonyPatch] internal static class MapItem { public const string PrefabName = "ZenMap"; private const int VariantCount = 10; private static Guid LastUsedMapID { get { if (!Player.m_localPlayer.m_customData.TryGetValue("ZenMap_LastUsedMapID", out var value)) { return Guid.Empty; } return Guid.Parse(value); } set { Player.m_localPlayer.m_customData["ZenMap_LastUsedMapID"] = value.ToString("N"); } } internal static Action? AddCraftingItem() { //IL_003d: 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_004d: 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_0063: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) Sprite[] array = (Sprite[])(object)new Sprite[10]; for (int i = 0; i < array.Length; i++) { array[i] = AssetIO.LoadSpriteFromResource((BaseUnityPlugin)(object)ZenMod.Instance, $"ItemIcons.map_item{i:00}.png"); } CustomItem val = new CustomItem("ZenMap", "ArmorRagsChest", new ItemConfig { Name = "$map_item", Description = "$map_item_description", CraftingStation = CraftingStations.None, MinStationLevel = 0, Requirements = Array.Empty(), Icons = array, Amount = 1, Weight = 0.1f, StackSize = 1 }); CustomItemExt.ApplyTextureToPrefab(val, array[0].texture, 0.5f, Vector2.one * 2f, Vector2.zero, "map", true, (Color?)null); ItemManager.Instance.AddItem(val); return null; } public static void ShowLastUsed() { Logging.Info((object)$"Last used map: {LastUsedMapID}", 0); Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); Guid guid2; ItemData val = ((IEnumerable)inventory.GetAllItems()).FirstOrDefault((Func)((ItemData item) => item.TryGetMapID(out guid2) && guid2 == LastUsedMapID)) ?? inventory.GetItem("ZenMap", -1, true); if (val == null) { MapMissing(); return; } val.TryGetMapID(out var guid); Logging.Info((object)$"Showing map: {guid}", 0); LastUsedMapID = guid; MapLocation mapLocation = MapLocation.ReadFrom(val); if (mapLocation == null) { MapMissing(); } else { mapLocation.Show(); } static void MapMissing() { Logging.Info((object)"Map not found", 0); ((Character)Player.m_localPlayer).Message((MessageType)2, "$map_error_missing", 0, (Sprite)null); } } public static int GetNextVariant() { Dictionary customData = Player.m_localPlayer.m_customData; string value; int num = (customData.TryGetValue("ZenMap_MapItemNextVariant", out value) ? int.Parse(value) : 0); customData["ZenMap_MapItemNextVariant"] = ((num + 1) % 10).ToString(); return num; } public static bool IsMapItem(this ItemData? item) { return ((item != null) ? ItemDataExt.GetPrefabName(item) : null) == "ZenMap"; } public static bool IsNear(this ItemData? item, Vector3 position, float maxDistance, out string mapItemLabel) { //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) mapItemLabel = string.Empty; if (item == null) { return false; } MapLocation mapLocation = MapLocation.ReadFrom(item); if (mapLocation == null) { return false; } mapItemLabel = mapLocation.Label; bool flag = MathExt.DistanceToXZ(mapLocation.Position, position) < maxDistance; Logging.Info((object)$"Is near origin table? {flag}", 0); return flag; } public static bool IsValidSeed(this ItemData item) { if (!item.m_customData.TryGetValue("ZenMap_seed", out var value)) { return false; } return int.Parse(value) == WorldGenerator.instance.GetSeed(); } private static bool TryGetMapID(this ItemData mapItem, out Guid guid) { guid = Guid.Empty; if (!mapItem.IsMapItem()) { return false; } if (mapItem.m_customData.TryGetValue("ZenMap_id", out var value)) { guid = Guid.Parse(value); } return guid != Guid.Empty; } internal static void CreateMapID(this ItemData mapItem) { if (!mapItem.IsMapItem()) { throw new ArgumentException("Item is not a MapItem"); } mapItem.m_customData["ZenMap_id"] = Guid.NewGuid().ToString("D"); } [HarmonyPrefix] [HarmonyPatch(typeof(Humanoid), "UseItem")] [HarmonyPriority(100)] private static void Humanoid_UseItem(Humanoid __instance, Inventory? inventory, ItemData? item, bool fromInventoryGui, ref bool __runOriginal) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || item == null || !item.IsMapItem() || !fromInventoryGui) { return; } if (inventory == null) { inventory = __instance.m_inventory; } if (!inventory.ContainsItem(item)) { return; } __runOriginal = false; if (!item.IsValidSeed()) { ((Character)__instance).Message((MessageType)2, "$map_error_alien", 0, (Sprite)null); return; } if (inventory == __instance.GetInventory() && item.TryGetMapID(out var guid)) { LastUsedMapID = guid; } MapLocation.ReadFrom(item)?.Show(); } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGrid), "CreateItemTooltip")] private static void InventoryGrid_CreateItemTooltip(InventoryGrid __instance, ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 if (item.IsMapItem()) { HintType activeType = KeyHint.ActiveType; if (activeType - 4 <= 1) { KeyHint.SetLabelOneFrame((HintName)15, StringExt.Localize("$hud_rename")); } } } [HarmonyPostfix] [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })] private static void ItemDrop_ItemData_GetTooltip(ItemData __instance, ref string __result) { if (!__instance.IsMapItem()) { return; } __instance.m_customData.TryGetValue("ZenMap_label", out var value); string text = "$map_item_description"; string text2 = string.Empty; if (!Utility.IsNullOrWhiteSpace(value)) { text2 += $"\n\n{value}"; } if (Configs.CalendarShow.Value) { string text3 = MapLocation.ReadFrom(__instance)?.GetCalendarString(); if (text3 != null) { if (Utility.IsNullOrWhiteSpace(value)) { text2 += "\n"; } text2 += $"\n{text3}"; } } if (!__instance.IsValidSeed()) { text2 += $"\n\n$map_error_alien"; } __result = __result.Replace("$map_item_description", text + text2); ItemDataExt.SetTooltipExtra(__instance, text2); } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] private static void InventoryGui_OnSelectedItem(InventoryGui __instance, ItemData item, Modifier mod, ref bool __runOriginal) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 ItemData item2 = item; if (item2.IsMapItem() && (int)mod == 1) { __runOriginal = false; MapLocation map = MapLocation.ReadFrom(item2, ignoreSeed: true); map?.PromptLabel(delegate { map.WriteTo(item2); }); } } } internal class MapLocation { private static MapLocation? _active; public readonly Vector3 Position; public readonly float Radius; public readonly float Percent; public readonly int WorldSeed; private double _timestamp; private string? _pinsBase64; private List? _pins; public static bool InUse => _active != null; public static MapLocation Active => _active ?? throw new InvalidOperationException("No active map location"); public string Label { get; private set; } public MapLocation(string label, Vector3 position, float radius) { //IL_000e: 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) Label = label; Position = position; if (!(radius > 0f)) { throw new ArgumentOutOfRangeException("radius", "must be positive"); } Radius = radius; Percent = Mathf.Clamp(Radius / (float)Configs.MapTableFullRadius.Value, 0f, 1f); WorldSeed = WorldGenerator.instance.GetSeed(); } private MapLocation(string label, Vector3 position, float radius, int worldSeed) : this(label, position, radius) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) WorldSeed = worldSeed; } public static bool IsMapTable() { if (InUse) { return !IsMapItem(); } return false; } public static bool IsMapItem() { List pins; return IsMapItem(out pins); } public static bool IsMapItem(out List pins) { pins = _active?._pins; return pins != null; } public void WriteTo(ItemData target) { //IL_003b: 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) Logging.Info((object)"Write map location to item", 0); target.CreateMapID(); Dictionary customData = target.m_customData; int worldSeed = WorldSeed; customData["ZenMap_seed"] = worldSeed.ToString(); target.m_customData["ZenMap_position"] = JsonUtility.ToJson((object)Position); Dictionary customData2 = target.m_customData; float radius = Radius; customData2["ZenMap_radius"] = radius.ToString("F"); target.m_customData["ZenMap_label"] = Label; target.m_customData["ZenMap_pins"] = _pinsBase64 ?? MapLocationPins.SerializePins(Position, Radius); target.m_customData["ZenMap_timestamp"] = BitConverter.DoubleToInt64Bits((_timestamp != 0.0) ? _timestamp : ZNet.instance.GetTimeSeconds()).ToString(); target.m_customData["ZenMap_version"] = 1.ToString(); } public static MapLocation? ReadFrom(ItemData source, bool ignoreSeed = false) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (!ignoreSeed && !source.IsValidSeed()) { Logging.Info((object)"Map item world seed does not match current world seed.", 0); return null; } Logging.Info((object)"Read map data from the item", 0); Dictionary customData = source.m_customData; if (customData.TryGetValue("ZenMap_position", out var value) && customData.TryGetValue("ZenMap_radius", out var value2) && customData.TryGetValue("ZenMap_label", out var value3) && customData.TryGetValue("ZenMap_seed", out var value4)) { string value5; MapLocation obj = new MapLocation(value3, JsonUtility.FromJson(value), float.Parse(value2), int.Parse(value4)) { _pinsBase64 = (customData.TryGetValue("ZenMap_pins", out value5) ? value5 : null) }; obj._pins = MapLocationPins.DeserializePins(obj._pinsBase64); obj._timestamp = (customData.TryGetValue("ZenMap_timestamp", out var value6) ? BitConverter.Int64BitsToDouble(long.Parse(value6)) : 0.0); return obj; } Logging.Warning((object)"Map item data missing or invalid location data. Was this map item instanced manually by admin?", 0); return null; } public void Show() { //IL_0022: 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) _active = this; Minimap.instance.Reset(); if (IsMapItem()) { MapLocationPins.ResetPinMarkers(); } Minimap.instance.Explore(Position, Radius); Minimap.instance.m_largeZoom = Mathf.Max(Map.Zoom.Min, Map.Zoom.Max * (Percent + 0.2f)); bool noMap = Game.m_noMap; Game.m_noMap = false; Minimap.instance.ShowPointOnMap(Position); Game.m_noMap = noMap; PlaySoundFX(); } public static void Close() { if (InUse) { MapLocationPins.ResetPinMarkers(); PlaySoundFX(); _active = null; } } private static void PlaySoundFX() { ((Humanoid)Player.m_localPlayer).TriggerEquipEffect((ItemData)null); } public void PromptLabel(Action onSuccess) { Action onSuccess2 = onSuccess; TextPrompt.Show("$map_item_prompt", Label, (Action)delegate(string input) { Label = StringExt.ToProperCase(StringExtensionMethods.RemoveRichTextTags(Regex.Replace(input, "\\$", string.Empty, RegexOptions.Multiline)).Trim(), false); Logging.Info((object)("Set text (sanitized): '" + Label + "'"), 0); onSuccess2(); }, 50); } private int GetCalendarYear(double defaultSeconds = -1.0) { int calendarDays = GetCalendarDays(defaultSeconds); int num = Configs.CalendarDaysPerYear.Value; if (num == 0) { num = 1; } return calendarDays / num + 1; } private int GetCalendarDays(double defaultSeconds = -1.0) { double num = ((_timestamp > 0.0) ? _timestamp : defaultSeconds); if (num < 0.0) { return 0; } return EnvMan.instance.GetDay(num) + Configs.CalendarInitDays.Value; } public string? GetCalendarString(double defaultSeconds = -1.0) { if (Configs.CalendarDaysPerYear.Value > 0) { int calendarYear = GetCalendarYear(defaultSeconds); if (calendarYear != 0) { return StringExt.Localize("$msg_calendar", new string[1] { calendarYear.ToString("N0", CultureInfo.CurrentCulture) }); } return null; } int calendarDays = GetCalendarDays(defaultSeconds); if (calendarDays != 0) { return "$hud_mapday " + calendarDays.ToString("N0", CultureInfo.CurrentCulture); } return null; } } internal static class MapParchment { public const string PrefabName = "ZenMapParchment"; internal static Action AddCraftingItem() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) Logging.Info((object)"Add crafting item: ZenMapParchment", 0); Sprite val = AssetIO.LoadSpriteFromResource((BaseUnityPlugin)(object)ZenMod.Instance, "ItemIcons.parchment.png"); ItemConfig val2 = new ItemConfig(); val2.Name = "$map_item_parchment"; val2.Description = "$map_item_parchment_description"; val2.CraftingStation = Configs.ParchmentCraftingStation.Value; val2.MinStationLevel = Configs.ParchmentCraftingStationLevel.Value; val2.Requirements = Configs.ParchmentResources.Value.ToRequirementConfigs(':'); val2.Icons = (Sprite[])(object)new Sprite[1] { val }; val2.Amount = 1; val2.Weight = 0.1f; val2.StackSize = 10; CustomItem item = new CustomItem("ZenMapParchment", "ArmorRagsChest", val2); CustomItemExt.ApplyTextureToPrefab(item, val.texture, 0.5f, Vector2.one, Vector2.zero, "", true, (Color?)null); ItemManager.Instance.AddItem(item); return ConfigSync; void ConfigSync() { Recipe recipe = item.Recipe.Recipe; recipe.m_craftingStation = PrefabManagerExt.GetCraftingStation(PrefabManager.Instance, Configs.ParchmentCraftingStation.Value); recipe.m_minStationLevel = Configs.ParchmentCraftingStationLevel.Value; recipe.m_resources = (Configs.MapItemEnabled.Value ? Configs.ParchmentResources.Value.ToRequirements(':') : Array.Empty()); } } public static bool IsMapParchment(this ItemData? item) { return ((item != null) ? ItemDataExt.GetPrefabName(item) : null) == "ZenMapParchment"; } } [HarmonyPatch] internal static class MapLocationPins { public class PinInfo { public Guid Guid; public PinType Type; public bool Checked; public Color Color; } private static readonly List ValidPins = new List(); private const int SerializeVersion = 1; public static void Shutdown() { ResetPinMarkers(); } public static void ResetPinMarkers() { foreach (PinData validPin in ValidPins) { Minimap instance = Minimap.instance; if (instance != null) { instance.DestroyPinMarker(validPin); } MapTrack.RemoveFromCache(validPin); } ValidPins.Clear(); if (Object.op_Implicit((Object)(object)Minimap.instance)) { CollectionExtensions.Do((IEnumerable)Minimap.instance.m_pins, (Action)Minimap.instance.DestroyPinMarker); Minimap.instance.m_pinUpdateRequired = true; } } public static string SerializePins(Vector3 origin, float range) { //IL_0007: 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) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected I4, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) List list = (from pin in Minimap.instance.m_pins where VectorExtensions.DistanceTo(origin, pin.m_pos) < range where Configs.PinShowMapItem.IsAllowed(pin.GetPrefabHash()) select pin).ToList(); ZPackage val = new ZPackage(); val.Write(1); val.Write(list.Count); foreach (PinData item in list) { Guid guid = item.GetGuid(); if (guid == Guid.Empty) { throw new Exception("Guid can not be empty"); } val.Write(guid.ToByteArray()); val.Write((int)item.m_type); val.Write(item.m_checked); val.Write(Color.white.ToUInt()); } string @base = val.GetBase64(); Logging.Info((object)$"Serialized pins: {list.Count}, bytes: {val.Size()}, base64 size: {@base.Length}", 0); return @base; } public static List DeserializePins(string? base64) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) if (base64 == null) { return new List(); } ZPackage val = new ZPackage(base64); int num = val.ReadInt(); if (num != 1) { Logging.Error((object)$"Map version mismatch. Expected {1}, got {num}", (ushort)0); return new List(); } List list = new List(); int num2 = val.ReadInt(); for (int i = 0; i < num2; i++) { PinInfo pinInfo = new PinInfo { Guid = new Guid(val.ReadByteArray()), Type = (PinType)val.ReadInt(), Checked = val.ReadBool(), Color = val.ReadUInt().ToColor() }; Logging.Info((object)$"Deserialized pin: {pinInfo.Guid}, type: {pinInfo.Type}", 0); list.Add(pinInfo); } Logging.Info((object)$"Deserialized pins: {list.Count}", 0); return list; } private static List MergeLocationPins() { if (!MapLocation.IsMapItem(out List pins)) { return Minimap.instance.m_pins; } if (ValidPins.Count > 0) { return ValidPins; } foreach (PinData pin in Minimap.instance.m_pins) { if (!IsHiddenOnMapItem(pin) && !pin.IsTracked()) { ValidPins.Add(CopyPin(pin)); } } foreach (PinInfo item2 in pins) { if (MapTrack.TryGetZDO(item2.Guid, out ZDO zdo)) { PinData item = CreateTempPin(zdo, item2); ValidPins.Add(item); } } return ValidPins; } private static bool IsHiddenOnMapItem(PinData pin) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected I4, but got Unknown bool flag = pin.m_shouldDelete; if (!flag) { PinType type = pin.m_type; bool flag2; switch (type - 5) { case 0: case 2: case 6: case 7: case 8: flag2 = true; break; default: flag2 = false; break; } flag = flag2; } return flag; } private static PinData CreateTempPin(ZDO zdo, PinInfo pinInfo) { //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_001c: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_004b: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown PinData val = new PinData { m_name = MapTrack.CreateTrackingLabel(zdo.GetLabel(), pinInfo.Guid), m_pos = zdo.GetPosition(), m_type = pinInfo.Type, m_icon = Minimap.instance.GetSprite(pinInfo.Type) }; val.m_NamePinData = new PinNameData(val); Logging.Info((object)("Pin Created: " + val.m_name), 0); return val; } private static PinData CopyPin(PinData pin) { //IL_000c: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_003e: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0092: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00ab: Expected O, but got Unknown Logging.Info((object)$"Copy pin: {pin.m_name} {pin.m_pos}", 0); PinData val = new PinData { m_name = pin.m_name, m_pos = pin.m_pos, m_type = pin.m_type, m_icon = pin.m_icon, m_checked = pin.m_checked, m_ownerID = pin.m_ownerID, m_author = pin.m_author, m_doubleSize = pin.m_doubleSize, m_worldSize = pin.m_worldSize, m_animate = pin.m_animate }; val.m_NamePinData = new PinNameData(val); return val; } [HarmonyTranspiler] [HarmonyPatch(typeof(Minimap), "UpdatePins")] private static IEnumerable Minimap_UpdatePins_MergePins(IEnumerable codes) { FieldInfo pinsField = AccessTools.Field(typeof(Minimap), "m_pins"); Func> intercept = MergeLocationPins; return Transpilers.Manipulator(codes, (Func)((CodeInstruction code) => CodeInstructionExtensions.Is(code, OpCodes.Ldfld, (MemberInfo)pinsField)), (Action)delegate(CodeInstruction code) { code.opcode = OpCodes.Call; code.operand = intercept.Method; }); } [HarmonyTranspiler] [HarmonyPatch(typeof(Minimap), "UpdatePins")] private static IEnumerable Minimap_UpdatePins_ColorPins(IEnumerable codes, ILGenerator gen) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00f0: Unknown result type (might be due to invalid IL or missing references) CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PinData), "m_iconElement"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.PropertySetter(typeof(Graphic), "color"), (string)null) }; Func func = AdjustPinColor; CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[4] { new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)6), new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)9), new CodeInstruction(OpCodes.Call, (object)func.Method), new CodeInstruction(OpCodes.Stloc_S, (object)(byte)9) }; return new CodeMatcher(codes, gen).MatchStartForward(array).ThrowIfInvalid("Unable to match IL").Insert(array2) .InstructionEnumeration(); } private static Color AdjustPinColor(PinData pin, Color defaultColor) { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (!Configs.PinColorEnabled.Value) { return defaultColor; } PinType type = pin.m_type; if ((int)type != 4) { if ((int)type == 9) { return Configs.PinColorBoss.Value; } if (pin.GetPrefabHash() == MapTrack.Pin.Sign) { return Configs.PinColorPrivate.Value; } if (MapTrack.Pin.Mounts.Contains(pin.GetPrefabHash())) { return Configs.PinColorPrivate.Value; } if (pin.IsTracked()) { return Configs.PinColorShared.Value; } return Configs.PinColorSpecial.Value; } return Configs.PinColorDeath.Value; } [HarmonyPrefix] [HarmonyPatch(typeof(Player), "OnSpawned")] private static void Player_OnSpawned() { ResetPinMarkers(); } } [HarmonyPatch] internal static class MapPinSelect { private static VariantDialog _dialog = null; private static Action? _onSelect; private static ItemData? _mapPinsIconData; private static readonly string[] PinDisplayOrder = new string[41] { "pickaxe", "axe", "sword", "bow", "anvil", "armor", "chest", "stackedbars", "potion", "cauldron", "tree", "berries", "berries2", "carrot", "turnip", "onion", "mushroom", "fish", "bee", "flower", "bread", "grain", "pig", "chicken", "wolf", "castle", "castle2", "tent", "bridge", "cave", "crystal", "magic_circle", "magic_eye", "magic_book", "swirl", "monster", "monster_trex", "dragon", "dragon2", "kraken", "question" }; private static readonly PinType[] PinnableTypes = ((IEnumerable)(object)new PinType[1] { (PinType)3 }).Union(PinDisplayOrder.Select(MapPinIcon.GetPinTypeFromResourceName)).ToArray(); public static bool IsOpen { get { if (Object.op_Implicit((Object)(object)_dialog)) { return ((Component)_dialog).gameObject.activeSelf; } return false; } } public static void Init() { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) _dialog = Object.Instantiate(InventoryGui.instance.m_variantDialog, Hud.instance.m_rootObject.transform); ((Component)_dialog).gameObject.SetActive(false); ((Object)_dialog).name = "ZenMap_PinSelect"; _dialog.m_selected = OnSelected; ((Graphic)((Component)_dialog.m_elementPrefab.transform.Find("Button")).GetComponent()).material = Materials.IconCleanTransparency; _mapPinsIconData = CreateMapPinsIconData(); RectTransform val = (RectTransform)_dialog.m_listRoot.parent; Vector2 anchoredPosition = val.anchoredPosition; anchoredPosition.y = -590f; val.anchoredPosition = anchoredPosition; val.sizeDelta = new Vector2(448f, 515f); } private static ItemData CreateMapPinsIconData() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_005b: Expected O, but got Unknown ItemData obj = ZNetScene.instance.GetPrefab("ZenMapPin").GetComponent().m_itemData.Clone(); obj.m_shared = new SharedData { m_icons = ((IEnumerable)PinnableTypes).Select((Func)Minimap.instance.GetSprite).ToArray(), m_variants = PinnableTypes.Length }; return obj; } private static GameObject CreateButton(Transform parent, string text, Action? onClick = null, Vector2 size = default(Vector2)) { //IL_003a: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) Action onClick2 = onClick; GameObject val = Object.Instantiate(((Component)Resources.FindObjectsOfTypeAll()[0].m_backButton).gameObject, parent, false); ((Object)val).name = "ZenMap_RemovePinBtn"; GuiButton component = val.GetComponent(); Navigation navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)component).navigation = navigation; ((UnityEventBase)((Button)component).onClick).RemoveAllListeners(); ((UnityEvent)((Button)component).onClick).AddListener(new UnityAction(ClickHandler)); ((Component)val.transform.Find("Label")).GetComponent().text = text; RectTransform val2 = (RectTransform)val.transform; val2.anchoredPosition = Vector2.one * 0.5f; val2.pivot = Vector2.one * 0.5f; if (size != default(Vector2)) { val2.sizeDelta = size; } Localization.instance.Localize(val.transform); return val; void ClickHandler() { onClick2?.Invoke(); } } public static void Choose(Action onSelect) { if (!IsOpen) { _onSelect = onSelect; _dialog.Setup(_mapPinsIconData); } } public static void CheckForInput() { if (IsOpen) { if (ZInput.GetKeyDown((KeyCode)27, true)) { Close(); } if (ZInput.GetButtonDown("JoyButtonB")) { Close(); } } } private static void Close() { _dialog.OnClose(); } public static void Shutdown() { if (Object.op_Implicit((Object)(object)_dialog)) { Object.Destroy((Object)(object)((Component)_dialog).gameObject); } } private static void OnSelected(int index) { Logging.Info((object)$"Selected index: {index}", 0); _onSelect?.Invoke(PinnableTypes[index]); Close(); } [HarmonyPrefix] [HarmonyPatch(typeof(VariantDialog), "OnClose")] private static void VariantDialog_OnClose(VariantDialog __instance) { if (!((Object)(object)__instance != (Object)(object)_dialog)) { _onSelect = null; PlayerController.SetTakeInputDelay(0.5f); } } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "IsVisible")] private static void InventoryGui_IsVisible(ref bool __result, ref bool __runOriginal) { __runOriginal = !IsOpen; __result = IsOpen; } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "Show")] private static void InventoryGui_Show() { if (IsOpen) { Close(); } } } [HarmonyPatch] internal static class MapUI { private const float IconPadding = 15f; private const float IconScale = 0.65f; private static readonly (string Name, PinType PinType, PinOption options)[] PinGroups = new(string, PinType, PinOption)[8] { ("Sign", (PinType)3, PinOption.Sign), ("Town", (PinType)1, PinOption.MapTable), ("Bonfire", (PinType)0, PinOption.Bonfire), ("Vehicle", (PinType)260, PinOption.Cart | PinOption.WarMachine), ("Ship", (PinType)258, PinOption.LargeShip | PinOption.SmallBoat), ("Portal", (PinType)6, PinOption.Portal), ("TombStone", (PinType)4, PinOption.Tombstone), ("BossAlter", (PinType)9, PinOption.None) }; private static RectTransform _iconPanel = null; private static RectTransform _iconPanel2 = null; private static RectTransform _keyHints = null; private static RectTransform _sharedPanel = null; private static RectTransform _publicPanel = null; private static Image _playerMarker = null; private static void DisableOriginalIcons() { Disable(Minimap.instance.m_selectedIcon0); Disable(Minimap.instance.m_selectedIcon1); Disable(Minimap.instance.m_selectedIcon2); Disable(Minimap.instance.m_selectedIcon3); Disable(Minimap.instance.m_selectedIcon4); Disable(Minimap.instance.m_selectedIconBoss); Disable(Minimap.instance.m_selectedIconDeath); static void Disable(Image img) { ((Component)((Component)img).transform.parent).gameObject.SetActive(false); } } public static void Show(bool isVisible) { //IL_0035: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_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_00a0: 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) ((Component)_iconPanel).gameObject.SetActive(isVisible); ((Component)_iconPanel2).gameObject.SetActive(isVisible); ((Component)_keyHints).gameObject.SetActive(isVisible); if (_sharedPanel.anchoredPosition.y > _publicPanel.anchoredPosition.y) { RectTransform sharedPanel = _sharedPanel; RectTransform publicPanel = _publicPanel; Vector2 anchoredPosition = _publicPanel.anchoredPosition; Vector2 anchoredPosition2 = _sharedPanel.anchoredPosition; sharedPanel.anchoredPosition = anchoredPosition; publicPanel.anchoredPosition = anchoredPosition2; sharedPanel = _sharedPanel; RectTransform publicPanel2 = _publicPanel; anchoredPosition2 = _publicPanel.pivot; anchoredPosition = _sharedPanel.pivot; sharedPanel.pivot = anchoredPosition2; publicPanel2.pivot = anchoredPosition; } ((Component)_sharedPanel).gameObject.SetActive(isVisible || !Map.IsNoMapKey); ((Component)_publicPanel).gameObject.SetActive(isVisible); ((Behaviour)_playerMarker).enabled = !Configs.HidePlayerArrow.Value || isVisible; } internal static void Init() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown Transform transform = Minimap.instance.m_largeRoot.transform; _iconPanel = (RectTransform)transform.Find("IconPanel"); _iconPanel2 = (RectTransform)transform.Find("IconPanel2"); _keyHints = (RectTransform)transform.Find("KeyHints"); _sharedPanel = (RectTransform)transform.Find("SharedPanel"); _publicPanel = (RectTransform)transform.Find("PublicPanel"); _playerMarker = ((Component)Minimap.instance.m_largeMarker).GetComponent(); } internal static void Shutdown() { } private static void InitNavIcons() { //IL_000f: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) _iconPanel.anchoredPosition = new Vector2(-39f, -100f); _iconPanel.anchorMax = new Vector2(1f, 1f); _iconPanel.anchorMin = new Vector2(1f, 0f); _iconPanel.pivot = new Vector2(0.5f, 0.5f); _iconPanel.sizeDelta = new Vector2(100f, -110f); ((Transform)_iconPanel).localScale = Vector3.one * 0.65f; ((Transform)_iconPanel).Find("iconhints").localScale = Vector3.one / 0.65f; GameObject gameObject = ((Component)((Component)Minimap.instance.m_selectedIcon1).transform.parent).gameObject; Minimap.instance.m_selectedIcons.Clear(); foreach (var item3 in IEnumerableExt.WithIndex<(string, PinType, PinOption)>((IEnumerable<(string, PinType, PinOption)>)PinGroups)) { (string, PinType, PinOption) item = item3.Item1; int item2 = item3.Item2; GameObject val = Object.Instantiate(gameObject, (Transform)(object)_iconPanel); Image component = val.GetComponent(); component.sprite = Minimap.instance.GetSprite(item.Item2); if (MapPinType.IsTrackedPin(item.Item2)) { Color color = Color.white * 0.8f; ((Graphic)component).color = color; } Transform transform = val.transform; Vector3 localPosition = transform.localPosition; Vector3 val2 = Vector3.down * (float)item2; Rect rect = ((Graphic)component).rectTransform.rect; transform.localPosition = localPosition + val2 * (((Rect)(ref rect)).height + 15f); ((Object)val).name = item.Item1; val.SetActive(true); SetupEventHandlers(val, item2); Minimap.instance.m_selectedIcons.Add(item.Item2, ((Component)val.transform.Find("Selected")).GetComponent()); } } private static void SetupEventHandlers(GameObject obj, int index) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown Button component = obj.GetComponent