Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BetterMapSeneaLCompatibility v0.3.3
BepInEx/plugins/BetterMapSeneaLCompat.dll
Decompiled a day agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("BetterMapSeneaLCompat")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.3.3.0")] [assembly: AssemblyInformationalVersion("0.3.3")] [assembly: AssemblyProduct("BetterMapSeneaLCompat")] [assembly: AssemblyTitle("BetterMapSeneaLCompat")] [assembly: AssemblyVersion("0.3.3.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 Ainzworth.BetterMapSeneaLCompat { [BepInPlugin("uk.ainzworth.valheim.bettermapsenealcompat", "BetterMapSeneaLCompatibility", "0.3.3")] [BepInDependency("xtav1m.BetterMap", "1.1.0")] [BepInDependency("seneaL.valheim.ui", "1.1.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { private const string ManualPrefix = "BetterMapSeneaL.manual."; private static readonly Dictionary<object, object[]> StyledTools = new Dictionary<object, object[]>(); private static readonly Dictionary<object, RectTransform> ToolRoots = new Dictionary<object, RectTransform>(); private static readonly Dictionary<object, object> DialogCategories = new Dictionary<object, object>(); private static Type _dialogType = null; private static object? _savingCategory; private static readonly FieldInfo Selected = AccessTools.Field(typeof(Minimap), "m_selectedType"); public const string Guid = "uk.ainzworth.valheim.bettermapsenealcompat"; private static Plugin? _instance; private Harmony? _harmony; private static int _syncDepth; private static Type _legend = null; private static IDictionary _types = null; private static IDictionary _categories = null; private static MethodInfo _iconFor = null; private static MethodInfo _invalidate = null; private static PropertyInfo _creatures = null; private static PropertyInfo _vehicles = null; private static readonly int VanillaCount = Enum.GetValues(typeof(PinType)).Length; private static readonly FieldInfo Visible = AccessTools.Field(typeof(Minimap), "m_visibleIconTypes"); private static readonly FieldInfo Pins = AccessTools.Field(typeof(Minimap), "m_pins"); private static readonly FieldInfo Dirty = AccessTools.Field(typeof(Minimap), "m_pinUpdateRequired"); private static MethodInfo _nameCategory = null; private static MethodInfo _recordHas = null; private static MethodInfo _recordLoad = null; private static MethodInfo _senealIcon = null; private static Type _chipBar = null; private static float _repairAt; private static float _filtersAt; private static readonly Dictionary<object, object> Bars = new Dictionary<object, object>(); private static readonly Dictionary<object, PinType[]> BarTypes = new Dictionary<object, PinType[]>(); private static readonly Regex CountSuffix = new Regex("\\s+[x×]\\s*\\d+$", RegexOptions.IgnoreCase); private static bool _repairFailed; private static bool _filtersFailed; private static string? ManualKey(PinData pin) { if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)ZNet.instance)) { return null; } return "BetterMapSeneaL.manual." + ZNet.instance.GetWorldUID().ToString(CultureInfo.InvariantCulture) + "." + pin.m_pos.x.ToString("R", CultureInfo.InvariantCulture) + "," + pin.m_pos.z.ToString("R", CultureInfo.InvariantCulture); } private static bool IsManual(PinData pin) { string text = ManualKey(pin); if (text != null) { return Player.m_localPlayer.m_customData.ContainsKey(text); } return false; } private static bool RestoreManual(PinData pin) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) string text = ManualKey(pin); if (text == null || !Player.m_localPlayer.m_customData.TryGetValue(text, out var value)) { return false; } foreach (object key in _types.Keys) { if (!(key.ToString() != value)) { pin.m_type = (PinType)_types[key]; pin.m_icon = CategorySprite(key); return true; } } return true; } private static Sprite CategorySprite(object category) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown string text = IconName(category); return (Sprite)((text == null) ? _iconFor.Invoke(null, new object[1] { category }) : _senealIcon.Invoke(null, new object[1] { text })); } private static void RequestCleanup() { if (Chainloader.PluginInfos.TryGetValue("uk.ainzworth.valheim.bettermapcleanup", out var value) && AccessTools.Field(((object)value.Instance).GetType(), "_cleanupNow")?.GetValue(value.Instance) is ConfigEntry<bool> val) { val.Value = true; } } private static void InstallManualPins(Harmony harmony, Assembly seneal) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_0095: 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_00b7: Expected O, but got Unknown //IL_00b7: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Expected O, but got Unknown //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Expected O, but got Unknown _dialogType = seneal.GetType("SeneaLUI.Map.PinDialog", throwOnError: true); harmony.Patch((MethodBase)AccessTools.Method(_dialogType, "Open_", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "DialogOpened", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(_dialogType, "UpdateGhost", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "UpdateManualGhost", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(_dialogType, "Save", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "BeforeSave", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AfterSave", (Type[])null), (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(_dialogType, "Close", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "DialogClosed", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Minimap), "AddPin", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "PinAdded", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Minimap), "RemovePin", new Type[1] { typeof(PinData) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "PinRemoved", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); if (Chainloader.PluginInfos.TryGetValue("uk.ainzworth.valheim.bettermapcleanup", out var value)) { MethodInfo methodInfo = ((object)value.Instance).GetType().GetNestedType("BetterMapRuntime", BindingFlags.NonPublic)?.GetMethod("TryGetCategory", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "KeepManual", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } } private static bool KeepManual(PinData __0, ref bool __result) { if (__0 == null || !IsManual(__0)) { return true; } __result = false; return false; } private static void PinAdded(PinData __result) { if (__result != null && _savingCategory != null) { string text = ManualKey(__result); if (text != null) { Player.m_localPlayer.m_customData[text] = _savingCategory.ToString(); } } } private static void PinRemoved(PinData __0) { if (__0 != null) { string text = ManualKey(__0); if (text != null) { Player.m_localPlayer.m_customData.Remove(text); } } } private static void DialogOpened(object __instance, PinType __1) { //IL_000b: 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_00ab: Unknown result type (might be due to invalid IL or missing references) DialogClosed(__instance); if (_categories.Contains(__1)) { object obj = _categories[__1]; DialogCategories[__instance] = obj; RectTransform[] array = (RectTransform[])Field(__instance, "_icons"); Image[] array2 = (Image[])Field(__instance, "_iconImg"); for (int i = 0; i < array.Length; i++) { ((Component)array[i]).gameObject.SetActive(i == 0); } AccessTools.Field(_dialogType, "_selected").SetValue(__instance, 0); array2[0].sprite = CategorySprite(obj); ((Image)Field(__instance, "_ghostIcon")).sprite = array2[0].sprite; } } private static void BeforeSave(object __instance, out PinType[]? __state) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected I4, but got Unknown __state = null; if (DialogCategories.TryGetValue(__instance, out object value)) { PinType[] array = (PinType[])AccessTools.Field(_dialogType, "Types").GetValue(null); __state = (PinType[])array.Clone(); array[0] = (PinType)(int)(PinType)_types[value]; AccessTools.Field(_dialogType, "_selected").SetValue(__instance, 0); _savingCategory = value; object obj = Field(__instance, "_edit"); PinData val = (PinData)((obj is PinData) ? obj : null); if (val != null && IsManual(val)) { PinAdded(val); } } } private static void UpdateManualGhost(object __instance) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (DialogCategories.TryGetValue(__instance, out object value)) { ((Image)Field(__instance, "_ghostIcon")).sprite = CategorySprite(value); } } private static void AfterSave(PinType[]? __state) { if (__state != null) { Array.Copy(__state, (Array)AccessTools.Field(_dialogType, "Types").GetValue(null), __state.Length); } _savingCategory = null; } private static void DialogClosed(object __instance) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown if (DialogCategories.Remove(__instance)) { RectTransform[] array = (RectTransform[])Field(__instance, "_icons"); for (int i = 0; i < array.Length; i++) { ((Component)array[i]).gameObject.SetActive(true); } string[] array2 = (string[])AccessTools.Field(_dialogType, "IconNames").GetValue(null); ((Image[])Field(__instance, "_iconImg"))[0].sprite = (Sprite)_senealIcon.Invoke(null, new object[1] { array2[0] }); } } private static void CopyRect(RectTransform from, RectTransform to) { //IL_0002: 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_001a: 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_003e: 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) to.anchorMin = from.anchorMin; to.anchorMax = from.anchorMax; to.pivot = from.pivot; to.sizeDelta = from.sizeDelta; to.anchoredPosition = from.anchoredPosition; ((Transform)to).localScale = ((Transform)from).localScale; ((Transform)to).localRotation = ((Transform)from).localRotation; } private static void CopyImage(Image from, Image to) { //IL_000e: 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) to.sprite = from.sprite; ((Graphic)to).color = ((Graphic)from).color; ((Graphic)to).material = ((Graphic)from).material; to.type = from.type; to.preserveAspect = from.preserveAspect; to.fillCenter = from.fillCenter; to.pixelsPerUnitMultiplier = from.pixelsPerUnitMultiplier; ((MaskableGraphic)to).maskable = ((MaskableGraphic)from).maskable; } private static void UpdateManualTools(object view, PinType[] types) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_054d: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_056c: Unknown result type (might be due to invalid IL or missing references) //IL_0571: Unknown result type (might be due to invalid IL or missing references) //IL_058a: Unknown result type (might be due to invalid IL or missing references) //IL_058f: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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_016d: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Expected O, but got Unknown //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Expected O, but got Unknown //IL_05c1: Unknown result type (might be due to invalid IL or missing references) //IL_05c6: Invalid comparison between Unknown and I4 //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Expected O, but got Unknown //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Expected O, but got Unknown //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Expected O, but got Unknown //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_0519: Unknown result type (might be due to invalid IL or missing references) //IL_0523: Expected O, but got Unknown foreach (object item in new List<object>(ToolRoots.Keys)) { if (!Object.op_Implicit((Object)(object)ToolRoots[item])) { ToolRoots.Remove(item); StyledTools.Remove(item); } } RectTransform val = (RectTransform)Field(view, "_toolsHost"); Rect rect; if (!ToolRoots.TryGetValue(view, out RectTransform value)) { Assembly assembly = view.GetType().Assembly; Type type = assembly.GetType("SeneaLUI.Components.Ui", throwOnError: true); Type type2 = assembly.GetType("SeneaLUI.Theme.Styles", throwOnError: true); Type type3 = assembly.GetType("SeneaLUI.Theme.Skin", throwOnError: true); object value2 = AccessTools.Field(type2, "Glass78").GetValue(null); object value3 = AccessTools.Field(type2, "ToolOn").GetValue(null); int num = (int)AccessTools.Property(value3.GetType(), "Pad").GetValue(value3, null); value = new GameObject("BetterMap pin tools", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)value).SetParent(((Transform)val).parent, false); RectTransform obj = value; RectTransform obj2 = value; RectTransform obj3 = value; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0f, 1f); obj3.pivot = val2; Vector2 anchorMin = (obj2.anchorMax = val2); obj.anchorMin = anchorMin; RectTransform obj4 = value; rect = val.rect; obj4.anchoredPosition = new Vector2(0f - ((Rect)(ref rect)).width - 4f, 0f); Sprite val4 = (Sprite)AccessTools.Method(type3, "Sliced", (Type[])null, (Type[])null).Invoke(null, new object[3] { 64, value2, -1 }); AccessTools.Method(type, "Panel", (Type[])null, (Type[])null).Invoke(null, new object[4] { value, val4, value2, false }); Component val5 = (Component)Field(view, "_toolsLabel"); if (Object.op_Implicit((Object)(object)val5)) { Object.Instantiate<GameObject>(val5.gameObject, (Transform)(object)value, false); } Array array = (Array)Field(view, "_tools"); object[] array2 = new object[types.Length]; StyledTools[view] = array2; for (int i = 0; i < types.Length; i++) { object value4 = array.GetValue(i); RectTransform val6 = (RectTransform)Field(value4, "Root"); RectTransform component = new GameObject(_categories[types[i]].ToString(), new Type[2] { typeof(RectTransform), typeof(Button) }).GetComponent<RectTransform>(); ((Transform)component).SetParent((Transform)(object)value, false); component.anchorMin = val6.anchorMin; component.anchorMax = val6.anchorMax; component.pivot = val6.pivot; component.sizeDelta = val6.sizeDelta; component.anchoredPosition = val6.anchoredPosition; Image val7 = (Image)AccessTools.Method(type, "Skinned", (Type[])null, (Type[])null).Invoke(null, new object[4] { component, Field(view, "_tool"), num, true }); ((Graphic)val7).raycastTarget = true; Image component2 = new GameObject("Icon", new Type[2] { typeof(RectTransform), typeof(Image) }).GetComponent<Image>(); ((Component)component2).transform.SetParent((Transform)(object)component, false); Image val8 = (Image)Field(value4, "Icon"); CopyRect(((Graphic)val8).rectTransform, ((Graphic)component2).rectTransform); CopyImage(val8, component2); component2.sprite = CategorySprite(_categories[types[i]]); ((Graphic)component2).color = ((Graphic)(Image)Field(value4, "Icon")).color; ((Graphic)component2).raycastTarget = false; object nativeStyle = Activator.CreateInstance(value4.GetType(), nonPublic: true); AccessTools.Field(nativeStyle.GetType(), "Root").SetValue(nativeStyle, component); AccessTools.Field(nativeStyle.GetType(), "Bg").SetValue(nativeStyle, val7); AccessTools.Field(nativeStyle.GetType(), "Icon").SetValue(nativeStyle, component2); array2[i] = nativeStyle; ((Component)component).gameObject.AddComponent<NativeToolHover>().Changed = delegate(bool entered) { AccessTools.Field(nativeStyle.GetType(), "Hover").SetValue(nativeStyle, entered); AccessTools.Method(view.GetType(), "PaintTool", (Type[])null, (Type[])null).Invoke(view, new object[1] { nativeStyle }); }; PinType selectedType = types[i]; Button component3 = ((Component)component).GetComponent<Button>(); ((Selectable)component3).targetGraphic = (Graphic)(object)val7; ((Selectable)component3).transition = (Transition)0; ((UnityEvent)component3.onClick).AddListener((UnityAction)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) AccessTools.Method(_legend, "Pressed", (Type[])null, (Type[])null).Invoke(null, new object[1] { selectedType }); }); } ToolRoots[view] = value; } CopyRect(val, value); RectTransform obj5 = value; Vector2 anchoredPosition = val.anchoredPosition; rect = val.rect; obj5.anchoredPosition = anchoredPosition - new Vector2(((Rect)(ref rect)).width + 4f, 0f); PinType val9 = (PinType)Selected.GetValue(Minimap.instance); object[] array3 = StyledTools[view]; for (int num2 = 0; num2 < types.Length; num2++) { object obj6 = array3[num2]; AccessTools.Field(obj6.GetType(), "On").SetValue(obj6, (int)val9 == (int)types[num2]); AccessTools.Method(view.GetType(), "PaintTool", (Type[])null, (Type[])null).Invoke(view, new object[1] { obj6 }); } } private void Awake() { //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Expected O, but got Unknown //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Expected O, but got Unknown //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Expected O, but got Unknown //IL_0243: Expected O, but got Unknown _instance = this; try { Assembly assembly = ((object)Chainloader.PluginInfos["xtav1m.BetterMap"].Instance).GetType().Assembly; Assembly assembly2 = ((object)Chainloader.PluginInfos["seneaL.valheim.ui"].Instance).GetType().Assembly; _legend = assembly.GetType("BetterMap.Scripts.Pins.PinLegend", throwOnError: true); _types = (IDictionary)AccessTools.Field(_legend, "_types").GetValue(null); _categories = (IDictionary)AccessTools.Field(_legend, "_categories").GetValue(null); _creatures = AccessTools.Property(_legend, "CreatureType"); _vehicles = AccessTools.Property(_legend, "VehicleType"); _iconFor = AccessTools.Method(assembly.GetType("BetterMap.Scripts.Icons", throwOnError: true), "For", (Type[])null, (Type[])null); Type? type = assembly2.GetType("SeneaLUI.Map.MapPins", throwOnError: true); _invalidate = AccessTools.Method(type, "Invalidate", (Type[])null, (Type[])null); MethodInfo methodInfo = AccessTools.Method(_legend, "Install", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(type, "KindOf", (Type[])null, (Type[])null); MethodInfo methodInfo3 = AccessTools.Method(type, "Sync", (Type[])null, (Type[])null); if (Visible == null || Pins == null || Dirty == null || _iconFor == null || _invalidate == null || methodInfo == null || methodInfo2 == null || methodInfo3 == null || _creatures == null || _vehicles == null) { throw new MissingMemberException("Unsupported map API"); } InitializePresentation(assembly, assembly2); _harmony = new Harmony("uk.ainzworth.valheim.bettermapsenealcompat"); _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "EnsureRegistration", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Plugin), "KeepBetterMapKind", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(Plugin), "BeginSync", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "EndSync", (Type[])null), (HarmonyMethod)null); InstallPresentation(_harmony, assembly2, assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Compatibility 0.3.3 installed: category repair, SeneaL styling and BetterMap filters."); } catch (Exception ex) { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } ((BaseUnityPlugin)this).Logger.LogError((object)("Compatibility disabled: " + ex)); } } private unsafe static bool Owns(PinType type) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 if (!_categories.Contains(type)) { if ((int)type >= VanillaCount) { object? value = _creatures.GetValue(null, null); if (!((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).Equals(value)) { object? value2 = _vehicles.GetValue(null, null); return ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).Equals(value2); } return true; } return false; } return true; } private static bool KeepBetterMapKind(PinType __0, ref int __result) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (_syncDepth == 0 || !Owns(__0)) { return true; } __result = 0; return false; } private static void BeginSync() { _syncDepth++; RepairPins(); } private static void EndSync() { _syncDepth = Math.Max(0, _syncDepth - 1); } private static void EnsureRegistration() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_005c: Expected I4, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: 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_0110: 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) Minimap instance = Minimap.instance; if (!Object.op_Implicit((Object)(object)instance)) { return; } try { bool[] array = (bool[])Visible.GetValue(instance); int num = Math.Max((array != null) ? array.Length : 0, VanillaCount); foreach (SpriteData icon in instance.m_icons) { num = Math.Max(num, icon.m_name + 1); } int num2 = 0; foreach (object item in (IEnumerable)AccessTools.Field(_legend, "Ours").GetValue(null)) { if (!_types.Contains(item)) { Sprite val = (Sprite)_iconFor.Invoke(null, new object[1] { item }); if (Object.op_Implicit((Object)(object)val)) { PinType val2 = (PinType)(num++); instance.m_icons.Add(new SpriteData { m_name = val2, m_icon = val }); _types[item] = val2; _categories[val2] = item; num2++; } } } if (num2 != 0) { bool[] array2 = new bool[num]; for (int i = 0; i < num; i++) { array2[i] = array == null || i >= array.Length || array[i]; } Visible.SetValue(instance, array2); Dirty.SetValue(instance, true); ((BaseUnityPlugin)_instance).Logger.LogInfo((object)$"Registered {num2} missing BetterMap categories independently of the vanilla legend layout."); } } catch (Exception ex) { ((BaseUnityPlugin)_instance).Logger.LogError((object)("Pin registration failed: " + ex)); } } private void OnDestroy() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } foreach (object value in Bars.Values) { RectTransform val = (RectTransform)Field(value, "Root"); if (Object.op_Implicit((Object)(object)val)) { Object.Destroy((Object)(object)((Component)val).gameObject); } } Bars.Clear(); BarTypes.Clear(); foreach (RectTransform value2 in ToolRoots.Values) { if (Object.op_Implicit((Object)(object)value2)) { Object.Destroy((Object)(object)((Component)value2).gameObject); } } ToolRoots.Clear(); StyledTools.Clear(); foreach (object item in new List<object>(DialogCategories.Keys)) { DialogClosed(item); } _instance = null; } private static void InitializePresentation(Assembly better, Assembly seneal) { _nameCategory = AccessTools.Method(better.GetType("BetterMap.Scripts.Pins.PinNames", throwOnError: true), "Category", (Type[])null, (Type[])null); Type? type = better.GetType("BetterMap.Scripts.Pins.PinRecord", throwOnError: true); _recordHas = AccessTools.Method(type, "Has", (Type[])null, (Type[])null); _recordLoad = AccessTools.Method(type, "Load", (Type[])null, (Type[])null); _senealIcon = AccessTools.Method(seneal.GetType("SeneaLUI.Theme.Icons", throwOnError: true), "Get", (Type[])null, (Type[])null); _chipBar = seneal.GetType("SeneaLUI.Components.ChipBar", throwOnError: true); } private static void InstallPresentation(Harmony harmony, Assembly seneal, Assembly better) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown InstallManualPins(harmony, seneal); harmony.Patch((MethodBase)AccessTools.Method(seneal.GetType("SeneaLUI.Map.MapPins"), "IconFor", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "ChooseIcon", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(seneal.GetType("SeneaLUI.Map.MapView"), "TickChips", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "UpdateFilters", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(better.GetType("BetterMap.Scripts.Pins.AutoPins"), "Restore", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AfterRestore", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static string? IconName(object category) { return category.ToString() switch { "Ore" => null, "Loot" => "chest", "Portal" => "portal", _ => null, }; } private static bool ChooseIcon(PinType __0, ref string? __result) { //IL_0005: 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) if (!_categories.Contains(__0)) { return true; } __result = IconName(_categories[__0]); return false; } private static void AfterRestore() { _repairAt = 0f; RepairPins(); } private static void RepairPins() { if (_repairFailed) { return; } try { RepairPinsCore(); } catch (Exception ex) { _repairFailed = true; ((BaseUnityPlugin)_instance).Logger.LogError((object)("Pin repair disabled: " + ex)); } } private static void RepairPinsCore() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Invalid comparison between Unknown and I4 //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Invalid comparison between Unknown and I4 //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_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)ZNetScene.instance) || Time.unscaledTime < _repairAt) { return; } _repairAt = Time.unscaledTime + 1f; if (!(Pins.GetValue(instance) is List<PinData> list)) { return; } _recordLoad.Invoke(null, null); int num = 0; foreach (PinData item in list) { if (RestoreManual(item) || ((int)item.m_type < VanillaCount && (int)item.m_type != 3)) { continue; } object[] array = new object[2] { CountSuffix.Replace(item.m_name ?? "", ""), null }; if (!(bool)_nameCategory.Invoke(null, array)) { continue; } object obj = array[1]; if (_types.Contains(obj) && ((int)item.m_type >= VanillaCount || (bool)_recordHas.Invoke(null, new object[3] { obj, item.m_pos, 1f }))) { PinType val = (PinType)_types[obj]; Sprite val2 = (Sprite)_iconFor.Invoke(null, new object[1] { obj }); if (item.m_type != val || !((Object)(object)item.m_icon == (Object)(object)val2)) { item.m_type = val; item.m_icon = val2; _invalidate.Invoke(null, new object[1] { item }); num++; } } } if (num > 0) { Dirty.SetValue(instance, true); RequestCleanup(); ((BaseUnityPlugin)_instance).Logger.LogInfo((object)$"Repaired category/icon assignments on {num} existing pins; checked state retained."); } } private static object Field(object target, string name) { return AccessTools.Field(target.GetType(), name).GetValue(target); } private static void UpdateFilters(object __instance) { if (_filtersFailed) { return; } try { UpdateFiltersCore(__instance); } catch (Exception ex) { _filtersFailed = true; ((BaseUnityPlugin)_instance).Logger.LogError((object)("BetterMap filter row disabled: " + ex)); } } private static void UpdateFiltersCore(object __instance) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)Minimap.instance) || _types.Count == 0 || (Bars.ContainsKey(__instance) && Time.unscaledTime < _filtersAt)) { return; } _filtersAt = Time.unscaledTime + 0.25f; RectTransform val = (RectTransform)Field(__instance, "_overlay"); if (!Object.op_Implicit((Object)(object)val)) { return; } foreach (object item in new List<object>(Bars.Keys)) { if (!Object.op_Implicit((Object)(RectTransform)Field(Bars[item], "Root"))) { Bars.Remove(item); BarTypes.Remove(item); } } if (!Bars.TryGetValue(__instance, out object value)) { List<PinType> list = new List<PinType>(); List<Sprite> list2 = new List<Sprite>(); foreach (object item2 in (IEnumerable)AccessTools.Field(_legend, "Ours").GetValue(null)) { if (_types.Contains(item2)) { list.Add((PinType)_types[item2]); string text = IconName(item2); list2.Add((Sprite)((text == null) ? _iconFor.Invoke(null, new object[1] { item2 }) : _senealIcon.Invoke(null, new object[1] { text }))); } } PinType[] captured = list.ToArray(); Action<int> action = delegate(int index) { if (Object.op_Implicit((Object)(object)Minimap.instance) && index >= 0 && index < captured.Length) { AccessTools.Method(_legend, "Filter", (Type[])null, (Type[])null).Invoke(null, new object[1] { captured[index] }); } }; value = Activator.CreateInstance(_chipBar, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[5] { val, "BetterMap filters", list2.ToArray(), false, action }, null); Bars[__instance] = value; BarTypes[__instance] = captured; } RectTransform val2 = (RectTransform)Field(value, "Root"); Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0f, 1f); val2.pivot = val3; Vector2 anchorMin = (val2.anchorMax = val3); val2.anchorMin = anchorMin; RectTransform val5 = (RectTransform)Field(Field(__instance, "_title"), "Root"); Vector3[] array = (Vector3[])(object)new Vector3[4]; val5.GetWorldCorners(array); Vector3 val6 = ((Transform)val).InverseTransformPoint(array[0]); float x = val6.x; Rect rect = val.rect; float num = x - ((Rect)(ref rect)).xMin; float y = val6.y; rect = val.rect; val2.anchoredPosition = new Vector2(num, y - ((Rect)(ref rect)).yMax - 12f); FieldInfo fieldInfo = AccessTools.Field(_chipBar, "MaxWidth"); object obj = value; rect = val.rect; fieldInfo.SetValue(obj, Math.Max(200f, ((Rect)(ref rect)).width - 100f)); PinType[] array2 = BarTypes[__instance]; string[] array3 = new string[array2.Length]; Dictionary<PinType, int> dictionary = new Dictionary<PinType, int>(); if (Pins.GetValue(Minimap.instance) is List<PinData> list3) { foreach (PinData item3 in list3) { dictionary.TryGetValue(item3.m_type, out var value2); dictionary[item3.m_type] = value2 + 1; } } bool[] array4 = (bool[])Visible.GetValue(Minimap.instance); Array array5 = (Array)Field(value, "_chips"); for (int num2 = 0; num2 < array2.Length; num2++) { dictionary.TryGetValue(array2[num2], out var value3); array3[num2] = _categories[array2[num2]]?.ToString() + " " + value3; object value4 = array5.GetValue(num2); int num3 = (int)array2[num2]; AccessTools.Field(value4.GetType(), "On").SetValue(value4, num3 < array4.Length && array4[num3]); AccessTools.Method(_chipBar, "Paint", (Type[])null, (Type[])null).Invoke(value, new object[1] { value4 }); } AccessTools.Method(_chipBar, "SetLabels", (Type[])null, (Type[])null).Invoke(value, new object[1] { array3 }); UpdateManualTools(__instance, array2); } } internal sealed class NativeToolHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler { internal Action<bool>? Changed; public void OnPointerEnter(PointerEventData eventData) { Changed?.Invoke(obj: true); } public void OnPointerExit(PointerEventData eventData) { Changed?.Invoke(obj: false); } private void OnDisable() { Changed?.Invoke(obj: false); } } }