using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
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.Lib;
using Zen.Lib.Config;
[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 DataKey
{
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";
}
[HarmonyPatch]
internal static class MapItem
{
public const string PrefabName = "ZenMap";
private const int VariantCount = 10;
private static Guid _lastUsedMapID;
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<Plugin>.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<RequirementConfig>(),
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<Plugin>.Info((object)$"Last used map: {_lastUsedMapID}", 0);
Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
Guid guid;
ItemData val = ((IEnumerable<ItemData>)inventory.GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData item) => item.TryGetMapID(out guid) && guid == _lastUsedMapID)) ?? inventory.GetItem("ZenMap", -1, true);
if (val == null)
{
MapMissing();
return;
}
val.TryGetMapID(out _lastUsedMapID);
Logging<Plugin>.Info((object)$"Showing map: {_lastUsedMapID}", 0);
MapLocation mapLocation = MapLocation.ReadFrom(val);
if (mapLocation == null)
{
MapMissing();
}
else
{
mapLocation.Show();
}
static void MapMissing()
{
Logging<Plugin>.Info((object)"Map not found", 0);
((Character)Player.m_localPlayer).Message((MessageType)2, "$map_error_missing", 0, (Sprite)null);
}
}
public static int GetNextVariant()
{
Dictionary<string, string> 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 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 CreateID(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_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_0006: 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_000a: Invalid comparison between Unknown and I4
HintType activeType = KeyHint.ActiveType;
if (activeType - 4 <= 1)
{
KeyHint.SetLabel("Split", item.IsMapItem() ? StringExt.Localize("$hud_rename") : StringExt.Localize("$inventory_splitstack"));
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UITooltip), "HideTooltip")]
private static void UITooltip_HideTooltip(UITooltip __instance)
{
//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_0006: 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_000a: Invalid comparison between Unknown and I4
HintType activeType = KeyHint.ActiveType;
if (activeType - 4 <= 1)
{
KeyHint.SetLabel("Split", StringExt.Localize("$inventory_splitstack"));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })]
private static void ItemDrop_ItemData_GetTooltip(ItemData __instance, ref string __result)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (__instance.IsMapItem())
{
__instance.m_customData.TryGetValue("ZenMap_label", out var value);
string text = "$map_item_description";
if (!Utility.IsNullOrWhiteSpace(value))
{
text += $"\n\n<color={UIColor.ValheimBeige}>{value}</color>";
}
if (!__instance.IsValidSeed())
{
text += $"\n\n<color={UIColor.Red}>$map_error_alien</color>";
}
__result = __result.Replace("$map_item_description", text);
}
}
[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;
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 void WriteTo(ItemData target)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Logging<Plugin>.Info((object)"Write map location to item", 0);
target.CreateID();
target.m_customData["ZenMap_position"] = JsonUtility.ToJson((object)Position);
Dictionary<string, string> customData = target.m_customData;
float radius = Radius;
customData["ZenMap_radius"] = radius.ToString("F");
target.m_customData["ZenMap_label"] = Label;
Dictionary<string, string> customData2 = target.m_customData;
int worldSeed = WorldSeed;
customData2["ZenMap_seed"] = worldSeed.ToString();
}
public static MapLocation? ReadFrom(ItemData source, bool ignoreSeed = false)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
if (!source.IsValidSeed() && !ignoreSeed)
{
Logging<Plugin>.Warning((object)"Map item world seed does not match current world seed.", 0);
return null;
}
Logging<Plugin>.Info((object)"Read map location from item", 0);
Dictionary<string, string> 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))
{
return new MapLocation(value3, JsonUtility.FromJson<Vector3>(value), float.Parse(value2), int.Parse(value4));
}
Logging<Plugin>.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_0011: 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)
_active = this;
MapFogCache.SaveAndReset();
Minimap.instance.Explore(Position, Radius);
Minimap.instance.m_largeZoom = Mathf.Max(Map.MinZoom, Map.MaxZoom * (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)
{
PlaySoundFX();
MapFogCache.Restore();
_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<string>)delegate(string input)
{
Label = StringExt.ToProperCase(StringExtensionMethods.RemoveRichTextTags(Regex.Replace(input, "\\$", string.Empty, RegexOptions.Multiline)).Trim(), false);
Logging<Plugin>.Info((object)("Set text (sanitized): '" + Label + "'"), 0);
onSuccess2();
}, 50);
}
}
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<Plugin>.Info((object)"Add crafting item: ZenMapParchment", 0);
Sprite val = AssetIO.LoadSpriteFromResource((BaseUnityPlugin)(object)ZenMod<Plugin>.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.EnableMapItems.Value ? Configs.ParchmentResources.Value.ToRequirements(':') : Array.Empty<Requirement>());
}
}
public static bool IsMapParchment(this ItemData? item)
{
return ((item != null) ? ItemDataExt.GetPrefabName(item) : null) == "ZenMapParchment";
}
}
[HarmonyPatch]
internal static class MapPinSelect
{
private static VariantDialog _dialog = null;
private static Action<PinType>? _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<PinType>)(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<VariantDialog>(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<Image>()).material = UI.CleanImageTransparency;
_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<ItemDrop>().m_itemData.Clone();
obj.m_shared = new SharedData
{
m_icons = ((IEnumerable<PinType>)PinnableTypes).Select((Func<PinType, Sprite>)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<GameObject>(((Component)Resources.FindObjectsOfTypeAll<Settings>()[0].m_backButton).gameObject, parent, false);
((Object)val).name = "ZenMap_RemovePinBtn";
GuiButton component = val.GetComponent<GuiButton>();
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<TMP_Text>().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<PinType> onSelect)
{
if (!IsOpen)
{
_onSelect = onSelect;
_dialog.Setup(_mapPinsIconData);
}
}
public static void Update()
{
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<Plugin>.Info((object)$"Selected index: {index}", 0);
_onSelect?.Invoke(PinnableTypes[index]);
Close();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Game), "Start")]
private static void Game_Start()
{
Init();
}
[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 PinBoss
{
public enum RevealMode
{
Never,
NearOnly,
Anywhere
}
private const float NearDistance = 20f;
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "DiscoverLocation")]
private static void Minimap_DiscoverLocation(PinType type, Vector3 pos, ref bool __runOriginal)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
//IL_0073: 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)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
if ((int)type != 9 || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
return;
}
if (((Character)Player.m_localPlayer).InGodMode())
{
Logging<Plugin>.Info((object)"God mode is enabled, use vanilla behavior", 0);
return;
}
Logging<Plugin>.Info((object)$"Boss pin reveal mode: {Configs.PinBossReveal.Value}", 0);
switch (Configs.PinBossReveal.Value)
{
case RevealMode.Never:
__runOriginal = false;
break;
case RevealMode.NearOnly:
if (MathExt.DistanceTo((MonoBehaviour)(object)Player.m_localPlayer, pos) > 20f)
{
__runOriginal = false;
}
break;
default:
throw new ArgumentOutOfRangeException();
case RevealMode.Anywhere:
break;
}
Logging<Plugin>.Info((object)(__runOriginal ? $"Revealing pin {MathExt.XZY(pos)}" : "Suppressing pin"), 0);
}
}
internal static class MapPin
{
public const string PrefabName = "ZenMapPin";
public static readonly Sprite Icon = AssetIO.LoadSpriteFromResource((BaseUnityPlugin)(object)ZenMod<Plugin>.Instance, "ItemIcons.pin_nail2.png");
internal static Action AddCraftingItem()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
//IL_00c5: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
Logging<Plugin>.Info((object)"Add crafting item: ZenMapPin", 0);
ItemConfig val = new ItemConfig();
val.Name = "$map_item_pin";
val.Description = "$map_item_pin_description";
val.CraftingStation = Configs.MapPinCraftingStation.Value;
val.MinStationLevel = Configs.MapPinCraftingStationLevel.Value;
val.Requirements = Configs.MapPinItemResources.Value.ToRequirementConfigs(':');
val.Icons = (Sprite[])(object)new Sprite[1] { Icon };
val.Amount = 1;
val.Weight = 0.1f;
val.StackSize = Configs.MapPinStackSize.Value;
CustomItem mapPinItem = new CustomItem("ZenMapPin", "Club", val);
CustomItemExt.ApplyTextureToPrefab(mapPinItem, Icon.texture, 0.35f, Vector2.one * 2f, Vector2.zero, "", true, (Color?)null);
ItemManager.Instance.AddItem(mapPinItem);
return ConfigSync;
void ConfigSync()
{
Recipe recipe = mapPinItem.Recipe.Recipe;
recipe.m_craftingStation = PrefabManagerExt.GetCraftingStation(PrefabManager.Instance, Configs.MapPinCraftingStation.Value);
recipe.m_minStationLevel = Configs.MapPinCraftingStationLevel.Value;
recipe.m_resources = Configs.MapPinItemResources.Value.ToRequirements(':');
recipe.m_item.m_itemData.m_shared.m_maxStackSize = Configs.MapPinStackSize.Value;
}
}
public static bool IsMapPin(this ItemData? item)
{
return ((item != null) ? ItemDataExt.GetPrefabName(item) : null) == "ZenMapPin";
}
}
[HarmonyPatch]
internal static class PinDeath
{
public static bool AllowAdd;
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "AddPin")]
private static void Minimap_AddPin(PinType type, ref bool __runOriginal)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
if ((int)type == 4 && !AllowAdd)
{
__runOriginal = false;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "LoadMapData")]
private static void Minimap_LoadMapData(Minimap __instance)
{
RemoveAllDeathPins(__instance);
}
private static void RemoveAllDeathPins(Minimap map)
{
PinData[] array = map.m_pins.Where((PinData pin) => (int)pin.m_type == 4).ToArray();
foreach (PinData item in array)
{
map.m_pins.Remove(item);
}
}
}
[HarmonyPatch]
internal static class MapFogCache
{
private static Texture2D? _cachedFog;
private static Texture2D? _emptyFog;
private static bool[]? _cachedExplored;
private static bool[]? _cachedExploredOthers;
private static bool _isCached;
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "Start")]
[HarmonyPriority(200)]
private static void Minimap_Start(Minimap __instance)
{
Init();
}
private static Color32[] CreateEmptyFogData(int width, int height)
{
//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)
Color32[] array = (Color32[])(object)new Color32[width * height];
for (int i = 0; i < array.Length; i++)
{
array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
}
return array;
}
internal static void Init()
{
//IL_003b: 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_0052: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
Logging<Plugin>.Info((object)"Initialize the fog cache", 0);
if (!Object.op_Implicit((Object)(object)Minimap.instance))
{
Logging<Plugin>.Error((object)"Minimap not initialized", (ushort)0);
return;
}
Texture2D fogTexture = Minimap.instance.m_fogTexture;
_cachedFog = new Texture2D(((Texture)fogTexture).width, ((Texture)fogTexture).height, fogTexture.format, ((Texture)fogTexture).mipmapCount, false, true);
_emptyFog = new Texture2D(((Texture)fogTexture).width, ((Texture)fogTexture).height, fogTexture.format, ((Texture)fogTexture).mipmapCount, false, true);
_emptyFog.SetPixels32(CreateEmptyFogData(((Texture)fogTexture).width, ((Texture)fogTexture).height));
_emptyFog.Apply();
_isCached = false;
}
private static void Reset()
{
if (!Object.op_Implicit((Object)(object)_emptyFog))
{
throw new Exception("Not initialized");
}
Logging<Plugin>.Info((object)"Reset the fog texture to the empty fog", 0);
Graphics.CopyTexture((Texture)(object)_emptyFog, (Texture)(object)Minimap.instance.m_fogTexture);
Logging<Plugin>.Info((object)"Reset the explored area", 0);
Minimap.instance.m_explored = new bool[Minimap.instance.m_explored.Length];
Minimap.instance.m_exploredOthers = new bool[Minimap.instance.m_exploredOthers.Length];
}
private static bool Save()
{
if (_isCached)
{
return false;
}
Logging<Plugin>.Info((object)"Save the current fog texture to the cache", 0);
Graphics.CopyTexture((Texture)(object)Minimap.instance.m_fogTexture, (Texture)(object)_cachedFog);
Logging<Plugin>.Info((object)"Save the current explored area to the cache", 0);
_cachedExplored = Minimap.instance.m_explored;
_cachedExploredOthers = Minimap.instance.m_exploredOthers;
_isCached = true;
return true;
}
public static void SaveAndReset()
{
if (Save())
{
Reset();
}
}
public static void Restore()
{
if (_isCached)
{
Logging<Plugin>.Info((object)"Restore the cached fog back to the fog texture", 0);
Graphics.CopyTexture((Texture)(object)_cachedFog, (Texture)(object)Minimap.instance.m_fogTexture);
Logging<Plugin>.Info((object)"Restore the cached explored area back to the explored area", 0);
Minimap.instance.m_explored = _cachedExplored;
Minimap.instance.m_exploredOthers = _cachedExploredOthers;
_isCached = false;
}
}
}
[HarmonyPatch]
internal static class MapPinType
{
private const int ReservedTypes = 128;
private const PinType ReservedStart = 256;
private const PinType ReservedEnd = 384;
internal const PinType UserPin = 288;
public const PinType Raft = 256;
public const PinType Karve = 257;
public const PinType VikingShip = 258;
public const PinType VikingShipAshlands = 259;
public const PinType Cart = 260;
public const PinType Catapult = 261;
public const PinType BatteringRam = 262;
public const PinType None = 8;
public const PinType Campfire = 0;
public const PinType House = 1;
public const PinType Hammer = 2;
public const PinType Dot = 3;
public const PinType Portal = 6;
public const PinType Death = 4;
public const PinType Boss = 9;
public const PinType Bed = 5;
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "Start")]
private static void Minimap_Start(Minimap __instance)
{
Minimap.instance.m_visibleIconTypes = Enumerable.Repeat(element: true, 384).ToArray();
}
}
[HarmonyPatch]
internal static class MapPinIcon
{
private static readonly Dictionary<string, PinType> NamedPinTypes;
private static readonly Dictionary<PinType, string> PinTypeToResource;
private static readonly Dictionary<string, Sprite> SpriteCache;
static MapPinIcon()
{
NamedPinTypes = new Dictionary<string, PinType>
{
["Raft"] = (PinType)256,
["Karve"] = (PinType)257,
["VikingShip"] = (PinType)258,
["VikingShip_Ashlands"] = (PinType)259,
["Cart"] = (PinType)260,
["Catapult"] = (PinType)261,
["BatteringRam"] = (PinType)262,
["Player_tombstone"] = (PinType)4,
["bonfire"] = (PinType)0,
["piece_cartographytable"] = (PinType)1,
["portal_wood"] = (PinType)6,
["portal_stone"] = (PinType)6
};
PinTypeToResource = new Dictionary<PinType, string>
{
[(PinType)3] = "flag",
[(PinType)256] = "vehicle_ship_raft",
[(PinType)257] = "vehicle_ship_karve",
[(PinType)258] = "vehicle_ship_longboat",
[(PinType)259] = "vehicle_ship_drakkar",
[(PinType)260] = "vehicle_cart",
[(PinType)261] = "vehicle_catapult",
[(PinType)262] = "vehicle_batteringram",
[(PinType)288] = "anvil",
[(PinType)289] = "cauldron",
[(PinType)290] = "pickaxe",
[(PinType)291] = "armor",
[(PinType)292] = "axe",
[(PinType)293] = "sword",
[(PinType)294] = "potion",
[(PinType)295] = "bow",
[(PinType)296] = "stackedbars",
[(PinType)297] = "chest",
[(PinType)298] = "tree",
[(PinType)299] = "berries",
[(PinType)300] = "berries2",
[(PinType)301] = "carrot",
[(PinType)302] = "turnip",
[(PinType)303] = "onion",
[(PinType)304] = "mushroom",
[(PinType)305] = "fish",
[(PinType)306] = "bee",
[(PinType)307] = "flower",
[(PinType)308] = "bread",
[(PinType)309] = "grain",
[(PinType)310] = "pig",
[(PinType)311] = "chicken",
[(PinType)312] = "wolf",
[(PinType)313] = "castle",
[(PinType)314] = "castle2",
[(PinType)315] = "tent",
[(PinType)316] = "bridge",
[(PinType)317] = "cave",
[(PinType)318] = "crystal",
[(PinType)319] = "magic_circle",
[(PinType)320] = "magic_eye",
[(PinType)321] = "magic_book",
[(PinType)322] = "swirl",
[(PinType)323] = "monster",
[(PinType)324] = "monster_trex",
[(PinType)325] = "dragon",
[(PinType)326] = "dragon2",
[(PinType)327] = "kraken",
[(PinType)328] = "question"
};
SpriteCache = new Dictionary<string, Sprite>();
Logging<Plugin>.Info((object)"Init sprite cache", 0);
SpriteCache.Clear();
foreach (string item in PinTypeToResource.Values.Distinct())
{
SpriteCache.Add(item, LoadSprite(item));
}
}
private static Sprite LoadSprite(string name)
{
//IL_0019: 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)
try
{
if (name.StartsWith("#"))
{
PinType val = (PinType)int.Parse(name.Substring(1));
return Minimap.instance.GetSprite(val);
}
if (name.StartsWith("$"))
{
string text = name.Substring(1);
GameObject prefab = ZNetScene.instance.GetPrefab(text);
if (Object.op_Implicit((Object)(object)prefab))
{
return prefab.GetComponent<Piece>().m_icon;
}
prefab = ObjectDB.instance.GetItemPrefab(text);
if (Object.op_Implicit((Object)(object)prefab))
{
return ItemDataExt.GetIcon(prefab.GetComponent<ItemDrop>());
}
throw new NullReferenceException("Prefab not found: " + name);
}
return AssetIO.LoadSpriteFromResource((BaseUnityPlugin)(object)ZenMod<Plugin>.Instance, "MapPins." + name + ".png");
}
catch (Exception innerException)
{
throw new Exception("Failed to load sprite: " + name, innerException);
}
}
private static PinType GetPrefabPinType(string prefabName)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (!NamedPinTypes.TryGetValue(prefabName, out var value))
{
return (PinType)3;
}
return value;
}
internal static PinType GetPinTypeFromResourceName(string name)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
string name2 = name;
return PinTypeToResource.First<KeyValuePair<PinType, string>>((KeyValuePair<PinType, string> kvp) => kvp.Value == name2).Key;
}
internal static PinType GetPinType(this ZDO zdo)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return GetPrefabPinType(ZdoExt.GetPrefabName(zdo));
}
private static Sprite? GetCustomIcon(PinType pinType)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (!PinTypeToResource.TryGetValue(pinType, out string value))
{
return null;
}
return SpriteCache[value];
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "GetSprite")]
private static void Minimap_GetSprite(PinType type, ref Sprite? __result, ref bool __runOriginal)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
Sprite customIcon = GetCustomIcon(type);
if (Object.op_Implicit((Object)(object)customIcon))
{
__result = customIcon;
__runOriginal = false;
}
}
}
[HarmonyPatch]
internal static class MapTrack
{
[HarmonyPatch(typeof(ZDOMan), "RPC_ZDOData")]
private static class ZDOMan_RPC_ZDOData
{
private static bool _isFromRPC;
[UsedImplicitly]
private static void Prefix()
{
_isFromRPC = true;
}
[UsedImplicitly]
private static void Postfix()
{
_isFromRPC = false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ZDO), "Deserialize")]
private static void ZDO_Deserialize(ZDO __instance)
{
if (_isFromRPC)
{
IndexAndPin(__instance);
}
else
{
Logging<Plugin>.Info((object)"ZDO.Deserialize called outside of RPC_ZDOData", 0);
}
}
}
private static readonly Dictionary<int, Func<bool>> AutoPinPrefabs = new Dictionary<int, Func<bool>>
{
{
StringExtensionMethods.GetStableHashCode("Raft"),
() => Configs.PinShowShip.Value
},
{
StringExtensionMethods.GetStableHashCode("Karve"),
() => Configs.PinShowShip.Value
},
{
StringExtensionMethods.GetStableHashCode("VikingShip"),
() => Configs.PinShowShip.Value
},
{
StringExtensionMethods.GetStableHashCode("VikingShip_Ashlands"),
() => Configs.PinShowShip.Value
},
{
StringExtensionMethods.GetStableHashCode("Cart"),
() => Configs.PinShowCart.Value
},
{
StringExtensionMethods.GetStableHashCode("Catapult"),
() => Configs.PinShowCart.Value
},
{
StringExtensionMethods.GetStableHashCode("BatteringRam"),
() => Configs.PinShowCart.Value
},
{
StringExtensionMethods.GetStableHashCode("Player_tombstone"),
() => Configs.PinShowTombstone.Value
},
{
StringExtensionMethods.GetStableHashCode("piece_cartographytable"),
() => Configs.PinShowMapTable.Value
},
{
StringExtensionMethods.GetStableHashCode("bonfire"),
() => Configs.PinShowBonfire.Value
}
};
private const string GuidPrefix = "GUID|";
private static readonly int ZDOVarGUID = StringExtensionMethods.GetStableHashCode("GUID|");
private static readonly Dictionary<Guid, ZDOID> GuidIndexZDOID = new Dictionary<Guid, ZDOID>();
private static readonly Dictionary<Guid, PinData> GuidIndexPin = new Dictionary<Guid, PinData>();
private static readonly Dictionary<PinData, Guid> PinToGuidCache = new Dictionary<PinData, Guid>();
private static bool _isIndexReady;
private const string DataDelimiter = "\0#";
private static readonly int DataSize;
internal static void Init()
{
_isIndexReady = false;
Logging<Plugin>.Info((object)"Waiting before rebuilding index...", 0);
Timing.Delay((MonoBehaviour)(object)ZenMod<Plugin>.Instance, 3f, (Action)delegate
{
RebuildIndex();
SetupAutoPins();
_isIndexReady = true;
});
}
internal static void Shutdown()
{
_isIndexReady = false;
}
private static void SetupAutoPins()
{
//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_002c: 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)
Logging<Plugin>.Debug((object)"Refreshing AutoPins", 0);
ZDOID[] array = GuidIndexZDOID.Values.ToArray();
foreach (ZDOID val in array)
{
ZDO zDO = ZDOMan.instance.GetZDO(val);
if (zDO == null)
{
Logging<Plugin>.Warning((object)$"ZDO is null for ZDOID: {val} - skipping.", 0);
}
else
{
AutoPinIfReq(zDO);
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "UpdateDynamicPins")]
private static void Minimap_UpdateDynamicPins(float dt)
{
if (_isIndexReady)
{
UpdatePins(dt);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "AddPin")]
private static void Minimap_AddPin(PinData? __result)
{
if (__result != null)
{
UpdateIndex(__result);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "RemovePin", new Type[] { typeof(PinData) })]
private static void Minimap_RemovePin(PinData? pin)
{
if (pin != null)
{
GuidIndexPin.Remove(pin.GetGuid());
PinToGuidCache.Remove(pin);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ZDOMan), "CreateSyncList")]
private static void ZDOMan_CreateSyncList(ZDOMan __instance)
{
if (!ZNet.IsSinglePlayer && ZNet.instance.IsServer())
{
CollectionExtensions.Do<ZDOID>((IEnumerable<ZDOID>)GuidIndexZDOID.Values, (Action<ZDOID>)__instance.ForceSendZDO);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")]
private static void ZDOMan_HandleDestroyedZDO(ZDOID uid)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (Game.instance.IsShuttingDown())
{
return;
}
Guid guid = ZDOMan.instance.GetZDO(uid).GetGuid();
if (guid != Guid.Empty)
{
Logging<Plugin>.Info((object)$"Remove Guid: {guid} for ZDOID: {uid}", 0);
GuidIndexZDOID.Remove(guid);
}
if (Object.op_Implicit((Object)(object)Minimap.instance))
{
PinData val = FindPin(guid);
if (val != null)
{
RemovePin(val);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ZDOMan), "FilterZDO")]
private static void ZDOMan_FilterZDO(ZDO? zdo)
{
if (zdo != null)
{
UpdateIndex(zdo);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ZDOMan), "GetZDO")]
private static void ZDOMan_GetZDO(ZDO? __result)
{
if (__result != null)
{
UpdateIndex(__result);
}
}
private static void IndexAndPin(ZDO zdo)
{
UpdateIndex(zdo);
AutoPinIfReq(zdo);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ZNetView), "Awake")]
private static void ZNetView_Awake(ZNetView __instance)
{
if (__instance.IsValid())
{
AutoPinIfReq(__instance.GetZDO());
}
}
private static bool IsAutoPinPrefab(ZDO zdo)
{
if (AutoPinPrefabs.TryGetValue(zdo.GetPrefab(), out Func<bool> value))
{
return value();
}
return false;
}
private static void AutoPinIfReq(ZDO zdo)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (IsAutoPinPrefab(zdo) && zdo.FindPin() == null)
{
Logging<Plugin>.Info((object)$"Adding autopin for ZDO: {ZdoExt.GetPrefabName(zdo)} {zdo.m_uid}", 0);
AddPin(zdo, save: false, (PinType)8);
}
}
private static void RebuildIndex()
{
Logging<Plugin>.Info((object)"Rebuilding Guid to ZDO index", 0);
GuidIndexZDOID.Clear();
foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
{
UpdateIndex(value);
if (ZNet.instance.IsServer() && IsAutoPinPrefab(value))
{
TrackZDO(value);
}
}
Logging<Plugin>.Info((object)"Rebuilding Guid to PinData index", 0);
GuidIndexPin.Clear();
PinToGuidCache.Clear();
foreach (PinData pin in Minimap.instance.m_pins)
{
UpdateIndex(pin);
}
}
private static Guid UpdateIndex(PinData pin)
{
Guid guid = pin.GetGuid();
if (guid != Guid.Empty)
{
GuidIndexPin[guid] = pin;
}
return guid;
}
private static Guid UpdateIndex(ZDO zdo)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Guid guid = zdo.GetGuid();
if (guid != Guid.Empty)
{
GuidIndexZDOID[guid] = zdo.m_uid;
}
return guid;
}
private static ZDOID LookupZDOID(Guid guid)
{
//IL_000d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
if (guid == Guid.Empty)
{
return ZDOID.None;
}
if (!GuidIndexZDOID.TryGetValue(guid, out var value))
{
return ZDOID.None;
}
return value;
}
private static Guid GetGuid(this ZDO? zdo)
{
byte[] array = ((zdo != null) ? zdo.GetByteArray(ZDOVarGUID, (byte[])null) : null);
if (array == null || array.Length != 16)
{
return Guid.Empty;
}
return new Guid(array);
}
private static string CreateTrackingLabel(string label, Guid guid)
{
if (label.Contains("\0#"))
{
throw new ArgumentException("label already contains guid, double guid encoding is not safe");
}
return label + "\0#" + guid.ToString("N");
}
private static Guid GetGuid(this PinData pin)
{
if (PinToGuidCache.TryGetValue(pin, out var value))
{
return value;
}
if (Utility.IsNullOrWhiteSpace(pin.m_name) || pin.m_name.Length < DataSize + "\0#".Length)
{
return Guid.Empty;
}
int num = pin.m_name.IndexOf("\0#"[0]);
if (num < 0 || num >= pin.m_name.Length - 1 || pin.m_name[num + 1] != "\0#"[1])
{
return Guid.Empty;
}
value = Guid.ParseExact(pin.m_name.Substring(num + "\0#".Length, DataSize), "N");
Logging<Plugin>.Info((object)$"Caching Pin: {value}", 0);
PinToGuidCache.Add(pin, value);
return value;
}
private static string GetLabel(this PinData pin)
{
int num = pin.m_name.IndexOf("\0#"[0]);
if (num >= 0)
{
return pin.m_name.Substring(0, num + 1);
}
return pin.m_name;
}
internal static PinData? FindPin(this ZDO zdo)
{
return FindPin(zdo.GetGuid());
}
private static PinData? FindPin(Guid guid)
{
if (!GuidIndexPin.TryGetValue(guid, out PinData value))
{
return null;
}
return value;
}
internal static void RemovePin(PinData pin)
{
//IL_000c: 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)
Logging<Plugin>.Info((object)$"Remove: {pin.m_name} {MathExt.XZY(pin.m_pos)}", 0);
Minimap.instance.RemovePin(pin);
}
private static Guid TrackZDO(ZDO zdo)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
Guid guid = zdo.GetGuid();
if (guid != Guid.Empty)
{
return guid;
}
ZNetView val = ZNetScene.instance.FindInstance(zdo);
if (Object.op_Implicit((Object)(object)val))
{
val.ClaimOwnership();
}
guid = Guid.NewGuid();
Logging<Plugin>.Info((object)$"Create new Guid: {guid} for zdo {zdo.m_uid}", 0);
zdo.Set(ZDOVarGUID, guid.ToByteArray());
UpdateIndex(zdo);
return guid;
}
private static bool TryGetZDO(this PinData pin, out ZDO zdo)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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)
ZDOID val = LookupZDOID(pin.GetGuid());
zdo = ZDOMan.instance.GetZDO(val);
return zdo != null;
}
private static bool IsSharedPin(PinData pin)
{
if (pin.m_ownerID != Player.m_localPlayer.GetPlayerID())
{
return pin.m_ownerID != 0;
}
return false;
}
private static void UpdatePins(float dt)
{
//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_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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_00cc: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Invalid comparison between Unknown and I4
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Invalid comparison between Unknown and I4
if (Game.instance.IsShuttingDown())
{
return;
}
List<PinData> pins = Minimap.instance.m_pins;
Ship ship = Player.m_localPlayer.GetControlledShip();
int num = pins.Count - 1;
while (num >= 0)
{
PinData pin = pins[num];
ZDO zdo;
if (IsSharedPin(pin))
{
Logging<Plugin>.Debug((object)"Shared pin found, ignoring", 0);
}
else if (!pin.TryGetZDO(out zdo))
{
if (pin.GetGuid() != Guid.Empty)
{
RemovePin(pin);
}
}
else
{
Vector3 position = zdo.GetPosition();
pin.m_pos = Vector3.MoveTowards(pin.m_pos, position, 200f * dt);
if (!MathExt.Approximately(pin.m_pos, position))
{
Minimap.instance.m_pinUpdateRequired = true;
}
MapMode mode = Minimap.instance.m_mode;
if ((int)mode > 1)
{
if ((int)mode != 2)
{
throw new ArgumentOutOfRangeException();
}
bool flag = Object.op_Implicit((Object)(object)ship) && (!Configs.HideShipMarker.Value || ((Character)Player.m_localPlayer).InGodMode());
((Component)Minimap.instance.m_largeShipMarker).gameObject.SetActive(flag);
ShowShipPin(!flag);
pin.SetLabel(zdo.GetLabel());
}
else
{
ShowShipPin(isVisible: false);
}
}
num--;
void ShowShipPin(bool isVisible)
{
ZDO obj = zdo;
Ship obj2 = ship;
if (obj == ((obj2 != null) ? obj2.m_nview.GetZDO() : null))
{
RectTransform uiElement = pin.m_uiElement;
if (uiElement != null)
{
((Component)uiElement).gameObject.SetActive(isVisible);
}
}
}
}
}
internal static void AddPin(ZDO zdo, bool save, PinType type = 8)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
//IL_0073: Invalid comparison between Unknown and I4
//IL_002f: 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_007f: Invalid comparison between Unknown and I4
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
if (zdo == null)
{
throw new NullReferenceException("ZDO can not be null");
}
PinData val = zdo.FindPin();
if (val != null)
{
Logging<Plugin>.Debug((object)$"Pin already exists: {val.GetGuid()} {val.m_name} {val.m_pos}", 0);
return;
}
string label = zdo.GetLabel();
Vector3 position = zdo.GetPosition();
Guid guid = TrackZDO(zdo);
string text = CreateTrackingLabel(label, guid);
Logging<Plugin>.Info((object)("Tracking Label: " + text), 0);
if ((int)type == 8)
{
type = zdo.GetPinType();
}
if ((int)type == 4 && Configs.PinShowTombstone.Value)
{
PinDeath.AllowAdd = true;
}
PinData val2 = Minimap.instance.AddPin(position, type, text, save, false, 0L, default(PlatformUserID));
PinDeath.AllowAdd = false;
if (val2 != null)
{
Logging<Plugin>.Info((object)$"Add pin type: {val2.m_type} {guid} {ZdoExt.GetPrefabName(zdo)} ({MathExt.XZY(position)}) ", 0);
}
}
private static void SetLabel(this PinData pin, string label)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
if (!Utility.IsNullOrWhiteSpace(label))
{
pin.m_name = CreateTrackingLabel(label, pin.GetGuid());
if (pin.m_NamePinData == null)
{
pin.m_NamePinData = new PinNameData(pin);
}
if (Object.op_Implicit((Object)(object)pin.m_NamePinData.PinNameText))
{
pin.m_NamePinData.PinNameText.text = pin.GetLabel();
}
}
}
private static string GetLabel(this ZDO zdo)
{
GameObject prefab = ZNetScene.instance.GetPrefab(zdo.GetPrefab());
Sign val = default(Sign);
string text = default(string);
if (prefab.TryGetComponent<Sign>(ref val) && zdo.GetString(ZDOVars.s_text, ref text))
{
if (!(text != val.m_defaultText))
{
return string.Empty;
}
return text;
}
MapTable val2 = default(MapTable);
if (prefab.TryGetComponent<MapTable>(ref val2))
{
string text2 = default(string);
if (zdo.GetString(ZDOVars.s_text, ref text2))
{
if (Utility.IsNullOrWhiteSpace(text2))
{
return StringExt.Localize("$map_region_default");
}
return text2;
}
return StringExt.Localize("$map_region_default");
}
TombStone val3 = default(TombStone);
if (prefab.TryGetComponent<TombStone>(ref val3))
{
string @string = zdo.GetString(ZDOVars.s_ownerName, "");
string text3 = StringExt.Localize(zdo.GetString(ZDOVars.s_text, ""));
if (Utility.IsNullOrWhiteSpace(text3))
{
return @string;
}
return @string + "\n(" + text3 + ")";
}
string text4 = string.Empty;
Piece val4 = default(Piece);
Hoverable val5 = default(Hoverable);
if (prefab.TryGetComponent<Piece>(ref val4))
{
text4 = val4.m_name;
}
else if (prefab.TryGetComponent<Hoverable>(ref val5))
{
text4 = val5.GetHoverName();
}
return StringExt.Localize(text4);
}
static MapTrack()
{
Guid empty = Guid.Empty;
DataSize = empty.ToString("N").Length;
}
}
[BepInPlugin("ZenDragon.ZenMap", "ZenMap", "0.7.10")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class Plugin : ZenMod<Plugin>
{
public const string PluginName = "ZenMap";
public const string PluginVersion = "0.7.10";
public const string PluginGUID = "ZenDragon.ZenMap";
protected override void Setup()
{
((ZenMod)this).RunOnServer = true;
base.RegisterCraftingItems += MapPin.AddCraftingItem;
base.RegisterCraftingItems += MapParchment.AddCraftingItem;
base.RegisterCraftingItems += MapItem.AddCraftingItem;
}
protected override void TitleScene(bool isFirstBoot)
{
}
protected override void HotRestore()
{
MapFogCache.Init();
MapPinSelect.Init();
}
protected override void WorldStart()
{
Configs.SetNoMap();
MapTrack.Init();
((MonoBehaviour)this).InvokeRepeating("CheckNoMapMode", 1f, 1f);
}
private void Update()
{
MapPinSelect.Update();
}
protected override void Shutdown()
{
MapTrack.Shutdown();
MapPinSelect.Shutdown();
}
private void CheckNoMapMode()
{
if (Configs.MapEnabledInGodMode.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
Game.m_noMap = ZoneSystem.instance.GetGlobalKey("nomap");
if (((Character)Player.m_localPlayer).InGodMode())
{
Game.m_noMap = false;
}
}
}
}
[HarmonyPatch]
internal static class Configs
{
public static readonly ConfigEntry<bool> MapEnabledInGodMode;
public static readonly ConfigEntry<int> MapTableDaysUntilFull;
public static readonly ConfigEntry<int> MapTableFullRadius;
public static readonly ConfigEntry<KeyCode> MapTableAdminAccelerateAgeKey;
public static readonly ConfigEntry<bool> AlwaysShowPlayers;
public static readonly ConfigEntry<bool> HideShipMarker;
public static readonly ConfigEntry<bool> HidePlayerArrow;
public static readonly ConfigEntry<bool> AutoSetNoMap;
public static readonly ConfigEntry<bool> HideMapPingInWorld;
public static readonly ConfigEntry<bool> HideShoutPings;
public static readonly ConfigEntry<PinBoss.RevealMode> PinBossReveal;
public static readonly ConfigEntry<bool> PinShowTombstone;
public static readonly ConfigEntry<bool> PinShowShip;
public static readonly ConfigEntry<bool> PinShowCart;
public static readonly ConfigEntry<bool> PinShowBonfire;
public static readonly ConfigEntry<bool> PinShowMapTable;
public static readonly ConfigEntry<KeyCode> PinShowLabelsKey;
public static readonly ConfigEntry<string> MapPinCraftingStation;
public static readonly ConfigEntry<int> MapPinCraftingStationLevel;
public static readonly ConfigEntry<StringList> MapPinItemResources;
public static readonly ConfigEntry<int> MapPinStackSize;
public static readonly ConfigEntry<bool> MapPinRefund;
public static readonly ConfigEntry<bool> EnableMapItems;
public static readonly ConfigEntry<string> ParchmentCraftingStation;
public static readonly ConfigEntry<int> ParchmentCraftingStationLevel;
public static readonly ConfigEntry<StringList> ParchmentResources;
public static readonly ConfigEntry<bool> DebugSantizeZDOs;
static Configs()
{
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Expected O, but got Unknown
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Expected O, but got Unknown
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Expected O, but got Unknown
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Expected O, but got Unknown
//IL_0295: Expected O, but got Unknown
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Expected O, but got Unknown
//IL_0305: Expected O, but got Unknown
AutoSetNoMap = Config.Define<bool>(true, "General", "Autoset World Modifier NoMap", true, "Automatically set the world modifier nomap on startup.\r\nIf nomap is enabled then the only way to view the map is via the cartography table (or admin god mode)");
HidePlayerArrow = Config.Define<bool>(true, "General", "Hide Player Arrow", true, "Hide the player's arrow icon when looking at the map table.\r\nInstead, use the landscape and compass to get your bearings.\r\n[close/open map to see changes]");
AlwaysShowPlayers = Config.Define<bool>(true, "General", "Show All Players Unless PVP", true, "Always show players on the map unless PVP is enabled.");
MapEnabledInGodMode = Config.Define<bool>(true, "General", "Map Enabled In God Mode", true, "Map key always enabled for admin when they are in God mode");
MapTableDaysUntilFull = Config.Define<int>(true, "General", "Days Until Full Map", 7, Config.AcceptRange<int>(0, 100), "How long must pass for a map table to be fully explored. (game days)");
MapTableFullRadius = Config.Define<int>(true, "General", "Map Table Fully Explored Radius", 2000, Config.AcceptRange<int>(400, 10000), "How large of an area does the fully explored map reveal");
MapTableAdminAccelerateAgeKey = Config.Define<KeyCode>(true, "General", "Admin Accelerate Age Key", (KeyCode)308, "Key that admin can hold while interacting with the table to accelerate its age. (God mode must be active)");
HideShipMarker = Config.Define<bool>(true, "General", "Hide Ship Marker", true, "Hide the ship marker (yellow banana) when the player is controlling a ship.");
HideMapPingInWorld = Config.Define<bool>(true, "General", "Map Ping - Hide In World", true, "When true the map ping can only be seen on the map table, not in the game world as floating text, not on the compass either.\r\nYou can still see each other's pings when both viewing the map table. Even if you are at different tables. \r\nThis prevents guiding players via ping spam. You have to talk to each other and plan ahead instead.");
HideShoutPings = Config.Define<bool>(true, "General", "Map Ping - Hide Shout Pings", true, "When true hides the shout pings from the cartograpy table large map.\r\nHowever, they can still be seen in world or on ZenCompass if you are in range.\r\nGod mode can always see all shout pings.");
PinShowLabelsKey = Config.Define<KeyCode>(false, "Pin Rules", "Show Labels Key", (KeyCode)304, "Hold down this key to display the pin labels on the map.\r\nNote: Gamepad is button Y.");
PinBossReveal = Config.Define<PinBoss.RevealMode>(true, "Pin Rules", "Boss Reveal", PinBoss.RevealMode.NearOnly, "Set the condition to display the boss pins. (Vanilla: Anywhere)\r\nNever: Never show the boss pins on the map.\r\nAnywhere: Add the boss pin to the map when you touch any Vegvisir anywhere in the world.\r\nNearOnly: Only add the boss pin to the map when you touch a Vegvisir close to the boss altar.");
PinShowTombstone = Config.Define<bool>(true, "Pin Rules", "Show Tombstones", true, "Display tombstone pins on the map. (Vanilla: true)\r\nTombstone pin markers are global, everyone can see the tombstone pins for all players.\r\n[restart required for changes to take effect]");
PinShowShip = Config.Define<bool>(true, "Pin Rules", "Show Ships", true, "Track all ships on the map and compass globally, everyone can see them.\r\nMap icon is various types of ships.\r\n[restart required for changes to take effect]");
PinShowCart = Config.Define<bool>(true, "Pin Rules", "Show Carts", true, "Track all carts, catapults, and battering rams on the map and compass globally, everyone can see them.\r\nMap icon is a cart.\r\n[restart required for changes to take effect]");
PinShowBonfire = Config.Define<bool>(true, "Pin Rules", "Show Bonfires", true, "Track all bonfires on the map globally, this is useful to create a shared marker for everyone to see.\r\nShows both player made and npc bonfires.\r\nMap icon is a fire.\r\n[restart required for changes to take effect]");
PinShowMapTable = Config.Define<bool>(true, "Pin Rules", "Show Cartography Tables", true, "Track all cartography tables on the map globally. \r\nHelps everyone see towns with other cartography tables in them so they know where to go for more info. \r\nMap icon is a house.\r\n[restart required for changes to take effect]");
EnableMapItems = Config.Define<bool>(true, "Crafting", "Enable Map Items", true, "When true the player can apply parchment to a cartography table and copy the table's map to an item.\r\nThe item can then be opened from anywhere in the world and it will always reflect that snapshot.\r\nThe map can be stored in chests or traded with other players. The map can be renamed.\r\nWhen false map items can not be created from the map table.\r\n[reboot required for changes to take effect]");
ParchmentCraftingStation = Config.Define<string>(true, "Crafting", "Parchment Crafting Station", "ArtisanTable", CraftingStations.GetAcceptableValueList(), "Crafting station required for creating a parchment.");
ParchmentCraftingStationLevel = Config.Define<int>(true, "Crafting", "Parchment Crafting Station Level", 1, Config.AcceptRange<int>(1, 5), "Minimum level required for the crafting station to craft parchment");
StringList val = new StringList();
((List<string>)val).Add("Resin:4");
((List<string>)val).Add("MeadTasty:2");
((List<string>)val).Add("Guck:3");
((List<string>)val).Add("LoxPelt:1");
ParchmentResources = Config.Define<StringList>(true, "Crafting", "Parchment Resources", val, "Resource requirements for crafting a parchment.");
MapPinCraftingStation = Config.Define<string>(true, "Crafting", "Map Pin Crafting Station", "None", CraftingStations.GetAcceptableValueList(), "Crafting station required for creating the map pin item.");
MapPinCraftingStationLevel = Config.Define<int>(true, "Crafting", "Map Pin Crafting Station Level", 1, Config.AcceptRange<int>(1, 5), "Minimum level required for the crafting station to craft map pins");
StringList val2 = new StringList();
((List<string>)val2).Add("BronzeNails:1");
MapPinItemResources = Config.Define<StringList>(true, "Crafting", "Map Pin Resources", val2, "Resource requirements for crafting a Map Pin.\r\nBronze nails is the default because it gives a perioid of early game progression without pins\r\nfor added challenge and reward.");
MapPinStackSize = Config.Define<int>(true, "Crafting", "Map Pin Stack Size", 100, Config.AcceptRange<int>(1, 100), "Max stack size. How many pins can be stored in a single inventory slot. [restart required for changes to take effect]");
MapPinRefund = Config.Define<bool>(true, "Crafting", "Map Pin Refund", true, "Refund the map pin when manually removing it from a sign?");
}
internal static void SetNoMap()
{
if (ZNet.instance.IsServer() && AutoSetNoMap.Value)
{
ZoneSystem.instance.SetGlobalKey((GlobalKeys)26);
Logging<Plugin>.Message((object)"World modifier enabled: NoMap", 0);
}
}
}
[HarmonyPatch]
internal static class Map
{
private static bool IsNoMapKey => ZoneSystem.instance.GetGlobalKey((GlobalKeys)26);
public static float MaxZoom => Mathf.Max(MinZoom, 0.385f / Minimap.instance.m_maxZoom * (float)Configs.MapTableFullRadius.Value / (Minimap.instance.m_maxZoom * 10000f));
public static float MinZoom => 0.015f / Minimap.instance.m_maxZoom;
private static float TimeElapsedSeconds(this MapTable table)
{
if (table.m_nview.IsValid())
{
return ZdoExt.GetAgeSeconds(table.m_nview.GetZDO());
}
Logging<Plugin>.Warning((object)"MapTable ZNetView invalid", 0);
return 0f;
}
private static void SetLabel(this MapTable table, string name)
{
table.m_nview.ClaimOwnership();
table.m_nview.GetZDO().Set(ZDOVars.s_text, name);
}
private static string GetLabel(this MapTable table)
{
if (!table.m_nview.IsValid())
{
return string.Empty;
}
return table.m_nview.GetZDO().GetString(ZDOVars.s_text, "");
}
private static MapLocation GetLocation(this MapTable table)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return new MapLocation(table.GetLabel(), ((Component)table).transform.position, table.ExploredRadius());
}
private static float ExploredRadius(this MapTable table)
{
float num = Mathf.Clamp(table.TimeElapsedSeconds() / (float)EnvMan.instance.m_dayLengthSec / (float)Configs.MapTableDaysUntilFull.Value, 0.05f, 1f);
return (float)Configs.MapTableFullRadius.Value * num;
}
private static int GetDaysRemaining(this MapTable table)
{
MapLocation location = table.GetLocation();
return Configs.MapTableDaysUntilFull.Value - Mathf.FloorToInt((float)Configs.MapTableDaysUntilFull.Value * location.Percent);
}
private static void AccelerateAge(this MapTable table, float seconds)
{
table.m_nview.ClaimOwnership();
ZdoExt.AccelerateAge(table.m_nview.GetZDO(), seconds);
}
private static void ApplyWriteFX(this MapTable table)
{
//IL_000e: 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)
Transform transform = ((Component)table).transform;
table.m_writeEffects.Create(transform.position, transform.rotation, (Transform)null, 1f, -1);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ZNet), "SendServerSyncPlayerData")]
private static void ZNet_SendServerSyncPlayerData(ZNet __instance)
{
if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Configs.AlwaysShowPlayers.Value)
{
__instance.SetPublicReferencePosition(!((Character)Player.m_localPlayer).IsPVPEnabled());
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "UpdateMap")]
private static void Minimap_UpdateMap(Minimap __instance, ref bool __runOriginal, float dt)
{
//IL_0013: 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)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
bool active = ZInput.GetButton("JoyButtonY") || ZInput.GetKey(Configs.PinShowLabelsKey.Value, true);
((Component)__instance.m_pinNameRootLarge).gameObject.SetActive(active);
if (MapLocation.InUse)
{
__runOriginal = false;
float num = ZInput.GetMouseScrollWheel() * __instance.m_largeZoom * 0.03f;
if (ZInput.GetButton("JoyLTrigger"))
{
num -= __instance.m_largeZoom * dt * 2f;
}
if (ZInput.GetButton("JoyRTrigger"))
{
num += __instance.m_largeZoom * dt * 2f;
}
__instance.m_largeZoom = Mathf.Clamp(__instance.m_largeZoom - num, MinZoom, MaxZoom);
((Component)__instance.m_gamepadCrosshair).gameObject.SetActive(false);
__instance.m_hints[0].SetActive(false);
__instance.UpdatePlayerMarker(Player.m_localPlayer, Quaternion.identity);
__instance.CenterMap(MapLocation.Active.Position);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerController), "TakeInput")]
private static void BlockMovementIfMapOpen(ref bool __runOriginal, ref bool __result)
{
if (Minimap.IsOpen() || MapPinSelect.IsOpen)
{
__result = false;
__runOriginal = false;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "Start")]
private static void Minimap_Start(Minimap __instance)
{
//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_0016: 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)
RectTransform val = (RectTransform)__instance.m_biomeNameLarge.transform;
Vector2 anchorMin = val.anchorMin;
anchorMin.x = 0f;
val.anchorMin = anchorMin;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "ShowPinNameInput")]
private static void Minimap_ShowPinNameInput(ref bool __runOriginal)
{
if (!((Character)Player.m_localPlayer).InGodMode())
{
__runOriginal = false;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "OnMapRightClick")]
private static void Minimap_OnMapRightClick(ref bool __runOriginal)
{
if (!ZInput.IsGamepadActive())
{
__runOriginal = ZInput.GetKey((KeyCode)306, true);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "IsPointVisible")]
private static void Minimap_IsPointVisible(Minimap __instance, Vector3 p, ref bool __result)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if (!((Character)Player.m_localPlayer).InGodMode())
{
__result = __result && __instance.IsExplored(p);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
private static void Minimap_UpdateExplore(Minimap __instance, ref bool __runOriginal)
{
__runOriginal = !MapLocation.InUse;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "SetMapMode")]
private static void Minimap_SetMapMode(Minimap __instance, MapMode mode)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
//IL_00d3: 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)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: 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)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
if ((int)mode != 2)
{
MapLocation.Close();
return;
}
SetAspectRatio();
Timing.NextFrame((MonoBehaviour)(object)__instance, (Action)delegate
{
if (InventoryGui.IsVisible())
{
InventoryGui.instance.Hide();
}
});
Transform transform = __instance.m_largeRoot.transform;
bool flag = ((Character)Player.m_localPlayer).InGodMode();
bool flag2 = (IsNoMapKey && !MapLocation.InUse && flag) || (!IsNoMapKey && flag);
((Component)transform.Find("IconPanel")).gameObject.SetActive(flag2);
((Component)transform.Find("IconPanel2")).gameObject.SetActive(flag2);
((Component)transform.Find("KeyHints")).gameObject.SetActive(flag2);
RectTransform val = (RectTransform)transform.Find("SharedPanel");
RectTransform val2 = (RectTransform)transform.Find("PublicPanel");
if (val.anchoredPosition.y > val2.anchoredPosition.y)
{
RectTransform val3 = val;
RectTransform val4 = val2;
Vector2 anchoredPosition = val2.anchoredPosition;
Vector2 anchoredPosition2 = val.anchoredPosition;
val3.anchoredPosition = anchoredPosition;
val4.anchoredPosition = anchoredPosition2;
val4 = val;
val3 = val2;
anchoredPosition2 = val2.pivot;
anchoredPosition = val.pivot;
val4.pivot = anchoredPosition2;
val3.pivot = anchoredPosition;
}
((Component)val).gameObject.SetActive(flag2 || !IsNoMapKey);
((Component)val2).gameObject.SetActive(flag2);
((Behaviour)((Component)__instance.m_largeMarker).GetComponent<Image>()).enabled = !Configs.HidePlayerArrow.Value || flag2;
}
private static void SetAspectRatio()
{
//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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
float num = (float)Screen.width / UI.ScaleFactor - 1620f;
RectTransform val = (RectTransform)Minimap.instance.m_largeRoot.transform;
Vector2 sizeDelta = val.sizeDelta;
sizeDelta.x = 0f - num;
val.sizeDelta = sizeDelta;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MapTable), "Start")]
private static void MapTable_Start(MapTable __instance)
{
if (__instance.m_nview.IsOwner())
{
ZdoExt.InitEpoch(__instance.m_nview.GetZDO());
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MapTable), "GetReadHoverText")]
private static void MapTable_GetReadHoverText(MapTable __instance, ref string __result, ref bool __runOriginal)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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)
if (IsNoMapKey)
{
__runOriginal = false;
__result = __instance.m_name + "\n" + UI.PromptInteract + " $piece_readmap";
if (WardAccessExt.CanAccessWard(((Component)__instance).transform.position, false))
{
__result = __result + "\n" + UI.PromptInteractAlt + " $hud_rename";
}
int daysRemaining = __instance.GetDaysRemaining();
if (daysRemaining > 0)
{
string arg = ((daysRemaining == 1) ? "$map_charting_single" : StringExt.Localize("$map_charting_plural", new string[1] { daysRemaining.ToString() }));
__result += $"\n<color={UIColor.MinorInfo}>{arg}</color>";
}
__result += $"\n\n<color={UIColor.MinorInfo}>{__instance.GetLabel()}</color>";
__result = StringExt.Localize(__result);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MapTable), "GetWriteHoverText")]
private static void MapTable_GetWriteHoverText(MapTable __instance, ref string __result, ref bool __runOriginal)
{
if (IsNoMapKey)
{
__runOriginal = false;
if (Configs.EnableMapItems.Value)
{
__result = __instance.m_name + "\n" + UI.PromptInteract + " $piece_writemap";
}
else
{
__result = string.Empty;
}
__result = StringExt.Localize(__result);
}
}
private static void PromptLabel(this MapTable table)
{
MapTable table2 = table;
TextPrompt.Show("$map_region_prompt", table2.GetLabel(), (Action<string>)delegate(string input)
{
table2.SetLabel(input);
((Character)Player.m_localPlayer).Message((MessageType)1, "$hud_rename: " + input, 0, GUIManager.Instance.GetSprite("cartography_table"));
}, 50);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Switch), "Interact")]
private static void Switch_Interact(Switch __instance, Humanoid character, bool hold, bool alt, ref bool __result, ref bool __runOriginal)
{
MapTable componentInParent = ((Component)__instance).GetComponentInParent<MapTable>();
if (Object.op_Implicit((Object)(object)componentInParent) && !((Object)(object)__instance != (Object)(object)componentInParent.m_readSwitch) && !(!alt || hold))
{
componentInParent.PromptLabel();
__runOriginal = false;
__result = true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
{
typeof(Switch),
typeof(Humanoid),
typeof(ItemData)
})]
private static void MapTable_OnRead(MapTable __instance, ref bool __runOriginal, ItemData? item)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
Logging<Plugin>.Debug((object)"Read the MapTable", 0);
if (!IsNoMapKey)
{
return;
}
__runOriginal = false;
if (item == null)
{
if (((Character)Player.m_localPlayer).InGodMode() && ZInput.GetKey(Configs.MapTableAdminAccelerateAgeKey.Value, true))
{
__instance.AccelerateAge(EnvMan.instance.m_dayLengthSec);
__instance.ApplyWriteFX();
((Character)Player.m_localPlayer).Message((MessageType)2, "Map table aged 1 day", 0, (Sprite)null);
}
else
{
__instance.GetLocation().Show();
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MapTable), "OnWrite")]
private static void MapTable_Write(MapTable __instance, Humanoid user, ItemData? item, ref bool __runOriginal, ref bool __result)
{
Humanoid user2 = user;
ItemData item2 = item;
MapTable __instance2 = __instance;
Logging<Plugin>.Debug((object)"Write the MapTable", 0);
if (!IsNoMapKey)
{
return;
}
__runOriginal = false;
__result = false;
if (!Configs.EnableMapItems.Value)
{
return;
}
if (item2 == null)
{
item2 = user2.GetInventory().GetItem("ZenMapParchment", -1, true);
}
if (!item2.IsMapParchment())
{
((Character)user2).Message((MessageType)2, "$msg_donthaveany $map_item_parchment", 0, (Sprite)null);
return;
}
__result = true;
MapLocation mapLocation = __instance2.GetLocation();
mapLocation.PromptLabel(delegate
{
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("ZenMap");
ItemData val = default(ItemData);
if (!InventoryExt.TryAddItem(user2.GetInventory(), itemPrefab, 1, ref val))
{
((Character)user2).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null);
}
else if (user2.GetInventory().RemoveItem(item2, 1))
{
((Character)user2).ShowRemovedMessage(item2, 1);
val.m_variant = MapItem.GetNextVariant();
mapLocation.WriteTo(val);
((Character)user2).Message((MessageType)2, "$msg_mapsynced", 0, (Sprite)null);
((Character)user2).ShowPickupMessage(val, 1);
__instance2.ApplyWriteFX();
}
else
{
Logging<Plugin>.Warning((object)("Unable to remove " + ItemDataExt.GetName(item2) + " from inventory."), 0);
}
});
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "Update")]
private static void Minimap_Update(Minimap __instance, ref bool __runOriginal)
{
if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Character)Player.m_localPlayer).InGodMode() && IsNoMapKey && !UI.IsOpen)
{
bool flag = ZInput.GetButtonDown("Map") || ZInput.GetButtonDown("JoyMap");
if (!MapLocation.InUse && flag)
{
MapItem.ShowLastUsed();
__runOriginal = false;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Minimap), "UpdateBiome")]
private static void Minimap_UpdateBiome(Minimap __instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
if (IsNoMapKey && MapLocation.InUse)
{
TMP_Text biomeNameLarge = __instance.m_biomeNameLarge;
biomeNameLarge.outlineColor = Color32.op_Implicit(Color.black);
biomeNameLarge.outlineWidth = 0.075f;
biomeNameLarge.alpha = 1f;
((Graphic)biomeNameLarge).color = Color.white;
if (ZInput.IsGamepadActive())
{
biomeNameLarge.text = string.Empty;
}
string label = MapLocation.Active.Label;
if (!Utility.IsNullOrWhiteSpace(label))
{
biomeNameLarge.text = "<size=30>" + label + "</size>\r\n" + biomeNameLarge.text;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Chat), "AddInworldText")]
private static void AddInWorldText(Type type, Vector3 position, ref bool __runOriginal)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
if ((int)Minimap.instance.m_mode != 2 && (int)type == 3)
{
__runOriginal = !Configs.HideMapPingInWorld.Value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Chat), "UpdateWorldTextField")]
private static void UpdateWorldTextField(WorldTextInstance wt)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)wt.m_type == 3 && Configs.HideMapPingInWorld.Value)
{
((Component)wt.m_textMeshField).gameObject.SetActive(false);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Minimap), "UpdateShoutPins")]
private static void UpdateShoutPins(Minimap __instance, ref bool __runOriginal)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Invalid comparison between Unknown and I4
if (Configs.HideShoutPings.Value && !((Character)Player.m_localPlayer).InGodMode() && (int)__instance.m_mode == 2)
{
__runOriginal = false;
CollectionExtensions.Do<PinData>((IEnumerable<PinData>)__instance.m_shoutPins, (Action<PinData>)__instance.RemovePin);
__instance.m_shoutPins.Clear();
}
}
}
[HarmonyPatch]
internal static class PinToSign
{
private static void AddPin(this Sign sign, PinType pinType)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
MapTrack.AddPin(sign.m_nview.GetZDO(), save: true, pinType);
((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_pin_added", 0, (Sprite)null);
}
private static bool HasPin(this Sign sign, out PinData pin)
{
return (pin = sign.m_nview.GetZDO().FindPin()) != null;
}
private static bool HasPin(this Sign sign)
{
PinData pin;
return sign.HasPin(out pin);
}
private static void RemovePin(this Sign sign)
{
PinData val = sign.m_nview.GetZDO().FindPin();
if (val == null)
{
Logging<Plugin>.Error((object)"Attempting to remove pin from sign that does not have a pin", (ushort)0);
return;
}
MapTrack.RemovePin(val);
((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_removed", 0, (Sprite)null);
}
private static bool RefundPin(this Sign sign)
{
ItemData itemData = ObjectDB.instance.GetItemPrefab("ZenMapPin").GetComponent<ItemDrop>().m_itemData;
Player localPlayer = Player.m_localPlayer;
if (((Humanoid)localPlayer).GetInventory().CanAddItem(itemData, 1))
{
sign.RemovePin();
((Humanoid)localPlayer).GetInventory().AddItem(itemData.m_dropPrefab, 1);
((Character)localPlayer).Message((MessageType)1, "$piece_tombstone_recovered", 1, itemData.GetIcon());
return true;
}
((Character)localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null);
return false;
}
private static string GetPromptUseMapPin(Sign sign)
{
Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
if (!InventoryExt.ContainsItemByPrefab(inventory, "ZenMapPin") && !InventoryExt.ContainsItemByPrefab(inventory, "Hammer"))
{
return string.Empty;
}
string text = ((sign.m_nview.GetZDO().FindPin() == null) ? "$hud_addpin" : "$hud_removepin");
return StringExt.Localize(UI.PromptUseItem + " " + text);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Sign), "GetHoverText")]
private static void Sign_GetHoverText(Sign __instance, ref string __result)
{
if (!__result.Contains(StringExt.Localize(UI.PromptUseItem)))
{
__result = __result + "\n" + GetPromptUseMapPin(__instance);
}
if (__instance.HasPin(out PinData pin))
{
HudExt.UpdateHoverIcons(Hud.instance, (Sprite[])(object)new Sprite[2]
{
MapPin.Icon,
pin.m_icon
});
string text = StringExt.Localize("$piece_sign");
string replacement = text + " «";
__result = Regex.Replace(__result, "^" + text, replacement, RegexOptions.Multiline);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Sign), "UseItem")]
private static void Sign_UseItem(Sign __instance, ItemData item, ref bool __result, ref bool __runOriginal)
{
ItemData item2 = item;
Sign __instance2 = __instance;
bool flag = ItemDataExt.GetPrefabName(item2) == "Hammer";
if ((!item2.IsMapPin() && !flag) || (flag && !__instance2.HasPin()))
{
return;
}
__runOriginal = false;
__result = true;
Player localPlayer = Player.m_localPlayer;
Inventory playerInventory = ((Humanoid)localPlayer).GetInventory();
if (((Character)localPlayer).InInterior())
{
((Character)localPlayer).Message((MessageType)2, "$msg_no_pin_indoors", 0, (Sprite)null);
__result = false;
}
else if (!__instance2.HasPin())
{
if (InventoryGui.IsVisible())
{
InventoryGui.instance.Hide();
}
MapPinSelect.Choose(delegate(PinType pinType)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
playerInventory.RemoveOneItem(item2);
__instance2.AddPin(pinType);
});
}
else if (Configs.MapPinRefund.Value)
{
__instance2.RefundPin();
}
else
{
__instance2.RemovePin();
}
}
}
}