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 MapRoutes v1.0.5
MapRoutes.dll
Decompiled 25 minutes agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("MapRoutes")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.5.0")] [assembly: AssemblyInformationalVersion("1.0.5")] [assembly: AssemblyProduct("MapRoutes")] [assembly: AssemblyTitle("MapRoutes")] [assembly: AssemblyVersion("1.0.5.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MapRoutes { internal static class ConfirmDialog { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Confirm; public static UnityAction <1>__Hide; } private static RectTransform _root; private static TextMeshProUGUI _messageLabel; private static Action _onConfirm; internal static void Build(Transform parent, TMP_FontAsset font) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_0295: 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_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_024d: 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_0258: Expected O, but got Unknown //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Expected O, but got Unknown if (!((Object)(object)parent.Find("MapRoutesConfirmDialog") != (Object)null)) { _root = CreateRect(parent, "MapRoutesConfirmDialog", new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 60f), new Vector2(360f, 110f)); Image val = ((Component)_root).gameObject.AddComponent<Image>(); Sprite itemBackground = ValheimUiSprites.ItemBackground; if ((Object)(object)itemBackground != (Object)null) { val.sprite = itemBackground; val.type = (Type)1; } ((Graphic)val).color = new Color(0.05f, 0.05f, 0.06f, 0.95f); _messageLabel = ((Component)CreateRect((Transform)(object)_root, "Message", new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -12f), new Vector2(-24f, 52f))).gameObject.AddComponent<TextMeshProUGUI>(); if ((Object)(object)font != (Object)null) { ((TMP_Text)_messageLabel).font = font; } ((TMP_Text)_messageLabel).text = "Точно очистить все линии? Это удалит и то, что нарисовали друзья, у всех."; ((TMP_Text)_messageLabel).fontSize = 13f; ((Graphic)_messageLabel).color = Color.white; ((TMP_Text)_messageLabel).alignment = (TextAlignmentOptions)514; ((TMP_Text)_messageLabel).textWrappingMode = (TextWrappingModes)1; ((Graphic)_messageLabel).raycastTarget = false; RectTransform obj = CreateRect((Transform)(object)_root, "Yes", new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(1f, 0f), new Vector2(-8f, 12f), new Vector2(150f, 32f)); Image val2 = ((Component)obj).gameObject.AddComponent<Image>(); if ((Object)(object)itemBackground != (Object)null) { val2.sprite = itemBackground; val2.type = (Type)1; } ((Graphic)val2).color = new Color(0.75f, 0.15f, 0.12f, 1f); Button obj2 = ((Component)obj).gameObject.AddComponent<Button>(); ((Selectable)obj2).targetGraphic = (Graphic)(object)val2; ButtonClickedEvent onClick = obj2.onClick; object obj3 = <>O.<0>__Confirm; if (obj3 == null) { UnityAction val3 = Confirm; <>O.<0>__Confirm = val3; obj3 = (object)val3; } ((UnityEvent)onClick).AddListener((UnityAction)obj3); CreateLabel(obj, "Да", Color.white, font, 14f); RectTransform obj4 = CreateRect((Transform)(object)_root, "Cancel", new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 0f), new Vector2(8f, 12f), new Vector2(150f, 32f)); Image val4 = ((Component)obj4).gameObject.AddComponent<Image>(); if ((Object)(object)itemBackground != (Object)null) { val4.sprite = itemBackground; val4.type = (Type)1; } ((Graphic)val4).color = new Color(0.4f, 0.4f, 0.4f, 1f); Button obj5 = ((Component)obj4).gameObject.AddComponent<Button>(); ((Selectable)obj5).targetGraphic = (Graphic)(object)val4; ButtonClickedEvent onClick2 = obj5.onClick; object obj6 = <>O.<1>__Hide; if (obj6 == null) { UnityAction val5 = Hide; <>O.<1>__Hide = val5; obj6 = (object)val5; } ((UnityEvent)onClick2).AddListener((UnityAction)obj6); CreateLabel(obj4, "Отмена", Color.white, font, 14f); ((Component)_root).gameObject.SetActive(false); } } internal static void Show(Action onConfirm) { if (!((Object)(object)_root == (Object)null)) { _onConfirm = onConfirm; ((Component)_root).gameObject.SetActive(true); ((Transform)_root).SetAsLastSibling(); } } private static void Hide() { if ((Object)(object)_root != (Object)null) { ((Component)_root).gameObject.SetActive(false); } _onConfirm = null; } private static void Confirm() { Action onConfirm = _onConfirm; Hide(); onConfirm?.Invoke(); } private static void CreateLabel(RectTransform parent, string text, Color color, TMP_FontAsset font, float fontSize) { //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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI val = ((Component)CreateRect((Transform)(object)parent, "Label", Vector2.zero, Vector2.one, new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero)).gameObject.AddComponent<TextMeshProUGUI>(); if ((Object)(object)font != (Object)null) { ((TMP_Text)val).font = font; } ((TMP_Text)val).text = text; ((TMP_Text)val).fontSize = fontSize; ((Graphic)val).color = color; ((TMP_Text)val).alignment = (TextAlignmentOptions)514; ((Graphic)val).raycastTarget = false; } private static RectTransform CreateRect(Transform parent, string name, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 anchoredPos, Vector2 size) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = anchorMin; val2.anchorMax = anchorMax; val2.pivot = pivot; val2.anchoredPosition = anchoredPos; val2.sizeDelta = size; return val2; } } internal class Stroke { public long Id; public readonly List<Vector3> Points = new List<Vector3>(); public Color Color; public float Thickness; } internal enum Tool { None, Draw, Erase } public class MapDrawingController : MonoBehaviour { private enum SyncState { NotStarted, WaitingForHost, Done } private readonly List<Stroke> _strokes = new List<Stroke>(); private Stroke _current; private bool _wasDrawing; private readonly List<Image> _poolLarge = new List<Image>(); private readonly List<Image> _poolSmall = new List<Image>(); private SyncState _syncState; private float _syncRequestTime; private const float SyncTimeout = 3f; private long _worldUID; internal static bool ShowDrawings = true; internal static Tool CurrentTool = Tool.None; internal static float LastActionTime = -999f; private const float SuppressWindow = 0.2f; internal static MapDrawingController Instance { get; private set; } internal static bool ShouldSuppressClick(KeyCode button) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (MapRoutesPlugin.ActionButton.Value == button) { return Time.time - LastActionTime < 0.2f; } return false; } private void Awake() { Instance = this; } private void OnDestroy() { if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } internal List<Stroke> GetAllStrokes() { return _strokes; } internal void RequestClearAll() { NetSync.BroadcastClear(); } internal void ApplyRemoteAdd(Stroke stroke) { foreach (Stroke stroke2 in _strokes) { if (stroke2.Id == stroke.Id) { return; } } _strokes.Add(stroke); SaveNow(); } internal void ApplyRemoteRemove(long strokeId) { for (int i = 0; i < _strokes.Count; i++) { if (_strokes[i].Id == strokeId) { _strokes.RemoveAt(i); SaveNow(); break; } } } internal void ApplyRemoteClear() { _strokes.Clear(); SaveNow(); } internal void ApplyFullSync(List<Stroke> strokes) { _strokes.Clear(); _strokes.AddRange(strokes); _syncState = SyncState.Done; SaveNow(); } private void SaveNow() { if (_syncState == SyncState.Done) { RouteStorage.Save(_worldUID, _strokes); } } private void Update() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Invalid comparison between Unknown and I4 NetSync.EnsureRegistered(); if (!MapRoutesPlugin.Enabled.Value) { HideAll(_poolLarge); HideAll(_poolSmall); return; } UpdateSync(); Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null || (int)instance.m_mode == 0) { _current = null; _wasDrawing = false; HideAll(_poolLarge); HideAll(_poolSmall); return; } bool flag = (int)instance.m_mode == 2; if (flag && !InTextInput() && ToolbarUI.IsExpanded && CurrentTool != Tool.None) { HandleInput(instance); } else { FinishDraw(); } if (!ShowDrawings) { HideAll(_poolLarge); HideAll(_poolSmall); } else if (flag) { RenderInto(instance, instance.m_mapImageLarge, instance.m_pinRootLarge, _poolLarge, useStoredThickness: true); HideAll(_poolSmall); } else { RenderInto(instance, instance.m_mapImageSmall, instance.m_pinRootSmall, _poolSmall, useStoredThickness: false); HideAll(_poolLarge); } } private void UpdateSync() { if (_syncState == SyncState.Done || (Object)(object)ZNet.instance == (Object)null) { return; } if (_syncState == SyncState.NotStarted) { _worldUID = ZNet.instance.GetWorldUID(); if (ZNet.instance.IsServer()) { _strokes.Clear(); _strokes.AddRange(RouteStorage.Load(_worldUID)); _syncState = SyncState.Done; } else { NetSync.RequestSync(); _syncRequestTime = Time.time; _syncState = SyncState.WaitingForHost; } } else if (_syncState == SyncState.WaitingForHost && Time.time - _syncRequestTime > 3f) { _strokes.Clear(); _strokes.AddRange(RouteStorage.Load(_worldUID)); _syncState = SyncState.Done; } } private void HandleInput(Minimap mm) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) KeyCode value = MapRoutesPlugin.ActionButton.Value; if (CurrentTool == Tool.Draw && ArmedMouseHeld(value)) { LastActionTime = Time.time; ContinueDraw(mm); } else if (CurrentTool == Tool.Erase && ArmedMouseDown(value)) { LastActionTime = Time.time; TryEraseNearCursor(mm); FinishDraw(); } else { FinishDraw(); } } private void ContinueDraw(Minimap mm) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) if (MinimapCoords.TryScreenToWorldPoint(mm, mm.m_mapImageLarge, Input.mousePosition, out var worldPos)) { if (_current == null) { _current = new Stroke { Id = StrokeSerializer.NewId(), Color = MapRoutesPlugin.GetDrawColor(), Thickness = MapRoutesPlugin.LineThickness.Value }; _current.Points.Add(worldPos); } else if (Vector3.Distance(_current.Points[_current.Points.Count - 1], worldPos) >= MapRoutesPlugin.MinPointSpacing.Value) { _current.Points.Add(worldPos); } } _wasDrawing = true; } private void FinishDraw() { if (_wasDrawing) { if (_current != null && _current.Points.Count >= 2) { NetSync.BroadcastAdd(_current); } _current = null; _wasDrawing = false; } } private void TryEraseNearCursor(Minimap mm) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //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_005c: Unknown result type (might be due to invalid IL or missing references) if (!MinimapCoords.TryScreenToWorldPoint(mm, mm.m_mapImageLarge, Input.mousePosition, out var worldPos)) { return; } float num = MapRoutesPlugin.EraseRadius.Value; long strokeId = 0L; bool flag = false; foreach (Stroke stroke in _strokes) { List<Vector3> points = stroke.Points; for (int i = 0; i < points.Count - 1; i++) { float num2 = DistancePointToSegment(worldPos, points[i], points[i + 1]); if (num2 < num) { num = num2; strokeId = stroke.Id; flag = true; } } } if (flag) { NetSync.BroadcastRemove(strokeId); } } private static float DistancePointToSegment(Vector3 p, Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Vector3 val = b - a; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; float num = ((sqrMagnitude > 0.0001f) ? Mathf.Clamp01(Vector3.Dot(p - a, val) / sqrMagnitude) : 0f); Vector3 val2 = a + val * num; return Vector3.Distance(p, val2); } private static int MouseIndex(KeyCode key) { //IL_0000: 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_0018: Expected I4, but got Unknown return (key - 323) switch { 0 => 0, 1 => 1, 2 => 2, _ => -1, }; } private static bool ArmedMouseHeld(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) int num = MouseIndex(key); if (num >= 0) { return Input.GetMouseButton(num); } return false; } private static bool ArmedMouseDown(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) int num = MouseIndex(key); if (num >= 0) { return Input.GetMouseButtonDown(num); } return false; } private static bool InTextInput() { if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible()) { return TextInput.IsVisible(); } return true; } private void RenderInto(Minimap mm, RawImage img, RectTransform parent, List<Image> pool, bool useStoredThickness) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (Stroke stroke in _strokes) { float thickness = (useStoredThickness ? stroke.Thickness : MapRoutesPlugin.MinimapLineThickness.Value); num = DrawStroke(mm, img, parent, pool, stroke.Points, stroke.Color, thickness, num); } if (_current != null && _current.Points.Count >= 2) { float thickness2 = (useStoredThickness ? _current.Thickness : MapRoutesPlugin.MinimapLineThickness.Value); num = DrawStroke(mm, img, parent, pool, _current.Points, _current.Color, thickness2, num); } for (int i = num; i < pool.Count; i++) { ((Component)pool[i]).gameObject.SetActive(false); } } private int DrawStroke(Minimap mm, RawImage img, RectTransform parent, List<Image> pool, List<Vector3> points, Color color, float thickness, int used) { //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) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < points.Count - 1; i++) { Vector2 val = MinimapCoords.WorldToLocalGuiPos(mm, img, points[i]); Vector2 val2 = MinimapCoords.WorldToLocalGuiPos(mm, img, points[i + 1]) - val; float magnitude = ((Vector2)(ref val2)).magnitude; if (!(magnitude < 0.01f)) { float num = Mathf.Atan2(val2.y, val2.x) * 57.29578f; Image pooledSegment = GetPooledSegment(parent, pool, used); RectTransform rectTransform = ((Graphic)pooledSegment).rectTransform; rectTransform.anchoredPosition = val; rectTransform.sizeDelta = new Vector2(magnitude, thickness); ((Transform)rectTransform).localRotation = Quaternion.Euler(0f, 0f, num); ((Graphic)pooledSegment).color = color; ((Component)pooledSegment).gameObject.SetActive(true); used++; } } return used; } private static Image GetPooledSegment(RectTransform parent, List<Image> pool, int index) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) if (index < pool.Count) { ((Transform)((Graphic)pool[index]).rectTransform).SetParent((Transform)(object)parent, false); return pool[index]; } GameObject val = new GameObject("MapRouteSegment", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent((Transform)(object)parent, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.zero; val2.pivot = new Vector2(0f, 0.5f); Image component = val.GetComponent<Image>(); ((Graphic)component).raycastTarget = false; pool.Add(component); return component; } private static void HideAll(List<Image> pool) { foreach (Image item in pool) { ((Component)item).gameObject.SetActive(false); } } } [HarmonyPatch(typeof(Minimap), "Awake")] internal static class Minimap_Awake_AddDrawingController { private static void Postfix(Minimap __instance) { if ((Object)(object)((Component)__instance).GetComponent<MapDrawingController>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<MapDrawingController>(); } } } [HarmonyPatch(typeof(Minimap), "OnMapLeftClick")] internal static class Minimap_OnMapLeftClick_Suppress { private static bool Prefix() { return !MapDrawingController.ShouldSuppressClick((KeyCode)323); } } [HarmonyPatch(typeof(Minimap), "OnMapRightClick")] internal static class Minimap_OnMapRightClick_Suppress { private static bool Prefix() { return !MapDrawingController.ShouldSuppressClick((KeyCode)324); } } [HarmonyPatch(typeof(Minimap), "OnMapMiddleClick")] internal static class Minimap_OnMapMiddleClick_Suppress { private static bool Prefix() { return !MapDrawingController.ShouldSuppressClick((KeyCode)325); } } internal static class MinimapCoords { internal static Vector2 WorldToLocalGuiPos(Minimap mm, RawImage img, Vector3 worldPos) { //IL_0001: 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) WorldToMapPoint(mm, worldPos, out var mx, out var my); return MapPointToLocalGuiPos(img, mx, my); } internal static bool TryScreenToWorldPoint(Minimap mm, RawImage img, Vector3 screenPos, out Vector3 worldPos) { //IL_000d: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)img).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); Vector2 val2 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, Vector2.op_Implicit(screenPos), (Camera)null, ref val2)) { Vector2 val3 = Rect.PointToNormalized(val.rect, val2); Rect uvRect = img.uvRect; float mx = ((Rect)(ref uvRect)).xMin + val3.x * ((Rect)(ref uvRect)).width; float my = ((Rect)(ref uvRect)).yMin + val3.y * ((Rect)(ref uvRect)).height; worldPos = MapPointToWorld(mm, mx, my); return true; } worldPos = Vector3.zero; return false; } private static void WorldToMapPoint(Minimap mm, Vector3 p, out float mx, out float my) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) int num = mm.m_textureSize / 2; mx = p.x / mm.m_pixelSize + (float)num; my = p.z / mm.m_pixelSize + (float)num; mx /= mm.m_textureSize; my /= mm.m_textureSize; } private static Vector3 MapPointToWorld(Minimap mm, float mx, float my) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) int num = mm.m_textureSize / 2; mx *= (float)mm.m_textureSize; my *= (float)mm.m_textureSize; mx -= (float)num; my -= (float)num; mx *= mm.m_pixelSize; my *= mm.m_pixelSize; return new Vector3(mx, 0f, my); } private static Vector2 MapPointToLocalGuiPos(RawImage img, float mx, float my) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) Rect uvRect = img.uvRect; Rect rect = ((Graphic)img).rectTransform.rect; Vector2 result = default(Vector2); result.x = (mx - ((Rect)(ref uvRect)).xMin) / ((Rect)(ref uvRect)).width * ((Rect)(ref rect)).width; result.y = (my - ((Rect)(ref uvRect)).yMin) / ((Rect)(ref uvRect)).height * ((Rect)(ref rect)).height; return result; } } internal static class NetSync { private const string MsgAdd = "MapRoutes_Add"; private const string MsgRemove = "MapRoutes_Remove"; private const string MsgClear = "MapRoutes_Clear"; private const string MsgRequestSync = "MapRoutes_RequestSync"; private const string MsgFullSync = "MapRoutes_FullSync"; private static ZRoutedRpc _registeredOn; internal static void EnsureRegistered() { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null && instance != _registeredOn) { instance.Register<ZPackage>("MapRoutes_Add", (Action<long, ZPackage>)RpcOnAdd); instance.Register<long>("MapRoutes_Remove", (Action<long, long>)RpcOnRemove); instance.Register("MapRoutes_Clear", (Action<long>)RpcOnClear); instance.Register("MapRoutes_RequestSync", (Action<long>)RpcOnRequestSync); instance.Register<ZPackage>("MapRoutes_FullSync", (Action<long, ZPackage>)RpcOnFullSync); _registeredOn = instance; } } internal static void BroadcastAdd(Stroke stroke) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown if (ZRoutedRpc.instance == null) { MapDrawingController.Instance?.ApplyRemoteAdd(stroke); return; } ZPackage val = new ZPackage(); StrokeSerializer.Write(val, stroke); ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "MapRoutes_Add", new object[1] { val }); } internal static void BroadcastRemove(long strokeId) { if (ZRoutedRpc.instance == null) { MapDrawingController.Instance?.ApplyRemoteRemove(strokeId); return; } ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "MapRoutes_Remove", new object[1] { strokeId }); } internal static void BroadcastClear() { if (ZRoutedRpc.instance == null) { MapDrawingController.Instance?.ApplyRemoteClear(); } else { ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "MapRoutes_Clear", Array.Empty<object>()); } } internal static void RequestSync() { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "MapRoutes_RequestSync", Array.Empty<object>()); } } private static void RpcOnAdd(long sender, ZPackage pkg) { Stroke stroke = StrokeSerializer.Read(pkg); MapDrawingController.Instance?.ApplyRemoteAdd(stroke); } private static void RpcOnRemove(long sender, long strokeId) { MapDrawingController.Instance?.ApplyRemoteRemove(strokeId); } private static void RpcOnClear(long sender) { MapDrawingController.Instance?.ApplyRemoteClear(); } private static void RpcOnRequestSync(long sender) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer()) { return; } MapDrawingController instance = MapDrawingController.Instance; if ((Object)(object)instance == (Object)null || ZRoutedRpc.instance == null) { return; } List<Stroke> allStrokes = instance.GetAllStrokes(); ZPackage val = new ZPackage(); val.Write(allStrokes.Count); foreach (Stroke item in allStrokes) { StrokeSerializer.Write(val, item); } ZRoutedRpc.instance.InvokeRoutedRPC(sender, "MapRoutes_FullSync", new object[1] { val }); } private static void RpcOnFullSync(long sender, ZPackage pkg) { int num = pkg.ReadInt(); List<Stroke> list = new List<Stroke>(num); for (int i = 0; i < num; i++) { list.Add(StrokeSerializer.Read(pkg)); } MapDrawingController.Instance?.ApplyFullSync(list); } } public enum DrawColorOption { Yellow, Red, Green, Blue, Orange, Purple, Cyan, Pink, White } [BepInPlugin("sopmehua.valheim.maproutes", "MapRoutes", "1.0.5")] public class MapRoutesPlugin : BaseUnityPlugin { public const string PluginGuid = "sopmehua.valheim.maproutes"; public const string PluginName = "MapRoutes"; public const string PluginVersion = "1.0.5"; public static ConfigEntry<bool> Enabled; public static ConfigEntry<float> LineThickness; public static ConfigEntry<float> MinimapLineThickness; public static ConfigEntry<float> MinPointSpacing; public static ConfigEntry<float> EraseRadius; public static ConfigEntry<KeyCode> ActionButton; public static ConfigEntry<DrawColorOption> DrawColor; private static ManualLogSource _log; private Harmony _harmony; public static Color GetDrawColor() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) return ColorFor(DrawColor.Value); } public static Color ColorFor(DrawColorOption option) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_008f: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) return (Color)(option switch { DrawColorOption.Red => new Color(0.95f, 0.2f, 0.2f, 0.95f), DrawColorOption.Green => new Color(0.25f, 0.9f, 0.3f, 0.95f), DrawColorOption.Blue => new Color(0.3f, 0.55f, 1f, 0.95f), DrawColorOption.Orange => new Color(1f, 0.55f, 0.1f, 0.95f), DrawColorOption.Purple => new Color(0.7f, 0.35f, 0.95f, 0.95f), DrawColorOption.Cyan => new Color(0.2f, 0.9f, 0.9f, 0.95f), DrawColorOption.Pink => new Color(1f, 0.45f, 0.75f, 0.95f), DrawColorOption.White => new Color(0.95f, 0.95f, 0.95f, 0.95f), _ => new Color(1f, 0.85f, 0.1f, 0.95f), }); } internal static void LogStatic(string message) { ManualLogSource log = _log; if (log != null) { log.LogInfo((object)message); } } private void Awake() { //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown _log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Включить/выключить мод."); LineThickness = ((BaseUnityPlugin)this).Config.Bind<float>("Drawing", "LineThickness", 4f, "Толщина линии на большой карте, пикселей."); MinimapLineThickness = ((BaseUnityPlugin)this).Config.Bind<float>("Drawing", "MinimapLineThickness", 2f, "Толщина линии на маленькой миникарте в углу экрана, пикселей."); DrawColor = ((BaseUnityPlugin)this).Config.Bind<DrawColorOption>("Drawing", "DrawColor", DrawColorOption.Yellow, "Цвет твоих линий. Каждая уже нарисованная линия сохраняет цвет, который был выбран в момент рисования."); MinPointSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Drawing", "MinPointSpacing", 2f, "Минимальное расстояние (в игровых метрах) между соседними точками линии — меньше точек, плавнее производительность."); EraseRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Drawing", "EraseRadius", 15f, "Радиус (в игровых метрах) вокруг курсора, в котором ищется ближайшая линия для стирания."); ActionButton = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ActionButton", (KeyCode)324, "Кнопка мыши для рисования/стирания (Mouse0=ЛКМ, Mouse1=ПКМ, Mouse2=СКМ). Работает только когда на панели выбран цвет или ластик."); _harmony = new Harmony("sopmehua.valheim.maproutes"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"MapRoutes 1.0.5 загружен (пока не сохраняется между сессиями)."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class RouteStorage { private const int Version = 2; private static string DirPath() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ".", "routes"); Directory.CreateDirectory(text); return text; } private static string FilePath(long worldUID) { return Path.Combine(DirPath(), worldUID + ".dat"); } internal static void Save(long worldUID, List<Stroke> strokes) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown try { ZPackage val = new ZPackage(); val.Write(2); val.Write(strokes.Count); foreach (Stroke stroke in strokes) { StrokeSerializer.Write(val, stroke); } File.WriteAllBytes(FilePath(worldUID), val.GetArray()); } catch (Exception ex) { MapRoutesPlugin.LogStatic("MapRoutes: save failed: " + ex); } } internal static List<Stroke> Load(long worldUID) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown List<Stroke> list = new List<Stroke>(); try { string path = FilePath(worldUID); if (!File.Exists(path)) { return list; } ZPackage val = new ZPackage(File.ReadAllBytes(path)); val.ReadInt(); int num = val.ReadInt(); for (int i = 0; i < num; i++) { list.Add(StrokeSerializer.Read(val)); } } catch (Exception ex) { MapRoutesPlugin.LogStatic("MapRoutes: load failed: " + ex); list.Clear(); } return list; } } internal static class StrokeSerializer { internal static void Write(ZPackage pkg, Stroke s) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) pkg.Write(s.Id); pkg.Write(s.Points.Count); foreach (Vector3 point in s.Points) { pkg.Write(point); } pkg.Write(s.Color.r); pkg.Write(s.Color.g); pkg.Write(s.Color.b); pkg.Write(s.Color.a); pkg.Write(s.Thickness); } internal static Stroke Read(ZPackage pkg) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) Stroke stroke = new Stroke { Id = pkg.ReadLong() }; int num = pkg.ReadInt(); for (int i = 0; i < num; i++) { stroke.Points.Add(pkg.ReadVector3()); } float num2 = pkg.ReadSingle(); float num3 = pkg.ReadSingle(); float num4 = pkg.ReadSingle(); float num5 = pkg.ReadSingle(); stroke.Color = new Color(num2, num3, num4, num5); stroke.Thickness = pkg.ReadSingle(); return stroke; } internal static long NewId() { return BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0); } } internal static class ToolbarUI { [CompilerGenerated] private static class <>O { public static UnityAction <0>__ToggleCollapsed; public static UnityAction <1>__ToggleVisibility; public static UnityAction <2>__ClearAll; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__23_0; public static UnityAction <>9__23_1; public static UnityAction <>9__23_2; public static Action <>9__30_0; internal void <Build>b__23_0() { SetTool(Tool.Erase); } internal void <Build>b__23_1() { ChangeSize(-1f); } internal void <Build>b__23_2() { ChangeSize(1f); } internal void <ClearAll>b__30_0() { MapDrawingController.Instance?.RequestClearAll(); } } private const float ButtonSize = 40f; private const float SwatchSize = 18f; private const float SwatchSpacing = 4f; private const float PanelPad = 12f; private const float RowGap = 10f; private const float CollapseButtonSize = 26f; private static readonly Color PanelTint = new Color(0.05f, 0.05f, 0.06f, 0.85f); private static readonly Color ButtonTint = new Color(1f, 1f, 1f, 0.5f); private static readonly Color SelectionTint = new Color(1f, 0.641f, 0f, 1f); private static readonly DrawColorOption[] Palette = new DrawColorOption[9] { DrawColorOption.Yellow, DrawColorOption.Red, DrawColorOption.Green, DrawColorOption.Blue, DrawColorOption.Orange, DrawColorOption.Purple, DrawColorOption.Cyan, DrawColorOption.Pink, DrawColorOption.White }; private static Image _eraserSelection; private static Image[] _colorSelections; private static RectTransform _sizeFillRect; private static float _sizeBarMaxWidth; private static TMP_FontAsset _font; private static Image _visibilityCheckmark; private static RectTransform _panel; private static RectTransform _content; private static Vector2 _expandedSize; private static bool _collapsed; private static TextMeshProUGUI _collapseGlyph; internal static bool IsExpanded { get { if ((Object)(object)_panel != (Object)null) { return !_collapsed; } return false; } } internal static void Build(Minimap mm) { //IL_0077: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0215: 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_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Expected O, but got Unknown //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Expected O, but got Unknown //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Expected O, but got Unknown //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0496: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_04f2: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_051d: Unknown result type (might be due to invalid IL or missing references) //IL_052c: Unknown result type (might be due to invalid IL or missing references) //IL_0531: Unknown result type (might be due to invalid IL or missing references) //IL_0540: Unknown result type (might be due to invalid IL or missing references) //IL_055f: Unknown result type (might be due to invalid IL or missing references) //IL_0592: Unknown result type (might be due to invalid IL or missing references) //IL_059c: Expected O, but got Unknown //IL_05db: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05f9: Unknown result type (might be due to invalid IL or missing references) //IL_0604: Unknown result type (might be due to invalid IL or missing references) //IL_0613: Unknown result type (might be due to invalid IL or missing references) //IL_0623: Unknown result type (might be due to invalid IL or missing references) //IL_06b6: Unknown result type (might be due to invalid IL or missing references) //IL_06c5: Unknown result type (might be due to invalid IL or missing references) //IL_06d4: Unknown result type (might be due to invalid IL or missing references) //IL_06dc: Unknown result type (might be due to invalid IL or missing references) //IL_06e8: Unknown result type (might be due to invalid IL or missing references) //IL_070c: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_073a: Unknown result type (might be due to invalid IL or missing references) //IL_0749: Unknown result type (might be due to invalid IL or missing references) //IL_0758: Unknown result type (might be due to invalid IL or missing references) //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0791: Unknown result type (might be due to invalid IL or missing references) //IL_07d4: Unknown result type (might be due to invalid IL or missing references) //IL_07e3: Unknown result type (might be due to invalid IL or missing references) //IL_07f2: Unknown result type (might be due to invalid IL or missing references) //IL_07fa: Unknown result type (might be due to invalid IL or missing references) //IL_0809: Unknown result type (might be due to invalid IL or missing references) //IL_0819: Unknown result type (might be due to invalid IL or missing references) //IL_065b: Unknown result type (might be due to invalid IL or missing references) //IL_0660: Unknown result type (might be due to invalid IL or missing references) //IL_0666: Expected O, but got Unknown //IL_08a8: Unknown result type (might be due to invalid IL or missing references) //IL_08b7: Unknown result type (might be due to invalid IL or missing references) //IL_08c6: Unknown result type (might be due to invalid IL or missing references) //IL_08d1: Unknown result type (might be due to invalid IL or missing references) //IL_08e2: Unknown result type (might be due to invalid IL or missing references) //IL_0906: Unknown result type (might be due to invalid IL or missing references) //IL_0851: Unknown result type (might be due to invalid IL or missing references) //IL_0856: Unknown result type (might be due to invalid IL or missing references) //IL_085c: Expected O, but got Unknown //IL_094f: Unknown result type (might be due to invalid IL or missing references) //IL_093a: Unknown result type (might be due to invalid IL or missing references) //IL_093f: Unknown result type (might be due to invalid IL or missing references) //IL_0945: Expected O, but got Unknown if ((Object)(object)mm.m_largeRoot.transform.Find("MapRoutesToolbar") != (Object)null) { return; } _font = (((Object)(object)mm.m_biomeNameLarge != (Object)null) ? mm.m_biomeNameLarge.font : null); float num = Mathf.Max((float)Palette.Length * 18f + (float)(Palette.Length - 1) * 4f, 88f) + 24f; float num2 = 166f; _expandedSize = new Vector2(num, num2); _panel = CreateRect(mm.m_largeRoot.transform, "MapRoutesToolbar", new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-20f, -90f), _expandedSize); AddPanelSprite(((Component)_panel).gameObject, PanelTint); RectTransform obj = CreateRect((Transform)(object)_panel, "CollapseButton", new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-6f, -6f), new Vector2(26f, 26f)); Image targetGraphic = AddPanelSprite(((Component)obj).gameObject, ButtonTint); Button obj2 = ((Component)obj).gameObject.AddComponent<Button>(); ((Selectable)obj2).targetGraphic = (Graphic)(object)targetGraphic; ButtonClickedEvent onClick = obj2.onClick; object obj3 = <>O.<0>__ToggleCollapsed; if (obj3 == null) { UnityAction val = ToggleCollapsed; <>O.<0>__ToggleCollapsed = val; obj3 = (object)val; } ((UnityEvent)onClick).AddListener((UnityAction)obj3); _collapseGlyph = CreateLabel(obj, "–", Color.white, 16f); _content = CreateRect((Transform)(object)_panel, "Content", Vector2.zero, Vector2.one, new Vector2(0f, 1f), Vector2.zero, Vector2.zero); _content.anchorMin = Vector2.zero; _content.anchorMax = Vector2.one; _content.offsetMin = Vector2.zero; _content.offsetMax = Vector2.zero; float num3 = -12f; RectTransform obj4 = CreateRect((Transform)(object)_content, "EraserButton", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(12f, num3), new Vector2(40f, 40f)); Image targetGraphic2 = AddPanelSprite(((Component)obj4).gameObject, ButtonTint); Button obj5 = ((Component)obj4).gameObject.AddComponent<Button>(); ((Selectable)obj5).targetGraphic = (Graphic)(object)targetGraphic2; ButtonClickedEvent onClick2 = obj5.onClick; object obj6 = <>c.<>9__23_0; if (obj6 == null) { UnityAction val2 = delegate { SetTool(Tool.Erase); }; <>c.<>9__23_0 = val2; obj6 = (object)val2; } ((UnityEvent)onClick2).AddListener((UnityAction)obj6); BuildCrossIcon(obj4); _eraserSelection = AddSelectionFrame(obj4); RectTransform obj7 = CreateRect((Transform)(object)_content, "VisibilityButton", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(60f, num3), new Vector2(40f, 40f)); Image val3 = ((Component)obj7).gameObject.AddComponent<Image>(); Sprite checkbox = ValheimUiSprites.Checkbox; if ((Object)(object)checkbox != (Object)null) { val3.sprite = checkbox; val3.type = (Type)1; } else { ((Graphic)val3).color = ButtonTint; } Button obj8 = ((Component)obj7).gameObject.AddComponent<Button>(); ((Selectable)obj8).targetGraphic = (Graphic)(object)val3; ButtonClickedEvent onClick3 = obj8.onClick; object obj9 = <>O.<1>__ToggleVisibility; if (obj9 == null) { UnityAction val4 = ToggleVisibility; <>O.<1>__ToggleVisibility = val4; obj9 = (object)val4; } ((UnityEvent)onClick3).AddListener((UnityAction)obj9); _visibilityCheckmark = ((Component)CreateRect((Transform)(object)obj7, "Checkmark", Vector2.zero, Vector2.one, new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(-8f, -8f))).gameObject.AddComponent<Image>(); Sprite checkboxMark = ValheimUiSprites.CheckboxMark; if ((Object)(object)checkboxMark != (Object)null) { _visibilityCheckmark.sprite = checkboxMark; } else { ((Graphic)_visibilityCheckmark).color = Color.white; } ((Graphic)_visibilityCheckmark).raycastTarget = false; num3 -= 50f; _colorSelections = (Image[])(object)new Image[Palette.Length]; for (int num4 = 0; num4 < Palette.Length; num4++) { DrawColorOption option = Palette[num4]; float num5 = 12f + (float)num4 * 22f; RectTransform val5 = CreateRect((Transform)(object)_content, "Color_" + option, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num5, num3), new Vector2(18f, 18f)); AddPanelSprite(((Component)val5).gameObject, new Color(1f, 1f, 1f, 0.35f)); Image val6 = ((Component)CreateRect((Transform)(object)val5, "Fill", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(12f, 12f))).gameObject.AddComponent<Image>(); ((Graphic)val6).color = MapRoutesPlugin.ColorFor(option); ((Graphic)val6).raycastTarget = false; Button obj10 = ((Component)val5).gameObject.AddComponent<Button>(); ((Selectable)obj10).targetGraphic = (Graphic)(object)val6; ((UnityEvent)obj10.onClick).AddListener((UnityAction)delegate { SelectColor(option); }); _colorSelections[num4] = AddSelectionFrame(val5); } num3 -= 28f; RectTransform obj11 = CreateRect((Transform)(object)_content, "SizeMinus", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(12f, num3), new Vector2(28f, 28f)); Image targetGraphic3 = AddPanelSprite(((Component)obj11).gameObject, ButtonTint); Button obj12 = ((Component)obj11).gameObject.AddComponent<Button>(); ((Selectable)obj12).targetGraphic = (Graphic)(object)targetGraphic3; ButtonClickedEvent onClick4 = obj12.onClick; object obj13 = <>c.<>9__23_1; if (obj13 == null) { UnityAction val7 = delegate { ChangeSize(-1f); }; <>c.<>9__23_1 = val7; obj13 = (object)val7; } ((UnityEvent)onClick4).AddListener((UnityAction)obj13); BuildBar(obj11, 14f, 3f, 0f); float num6 = num - 24f - 28f - 28f - 16f; float num7 = 48f; RectTransform obj14 = CreateRect((Transform)(object)_content, "SizeBarBg", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num7, num3), new Vector2(num6, 28f)); ((Graphic)AddPanelSprite(((Component)obj14).gameObject, new Color(1f, 1f, 1f, 0.3f))).raycastTarget = false; RectTransform obj15 = CreateRect((Transform)(object)obj14, "SizeBarFillHolder", new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(4f, 0f), new Vector2(8f, 8f)); Image obj16 = ((Component)obj15).gameObject.AddComponent<Image>(); ((Graphic)obj16).color = new Color(1f, 1f, 1f, 0.85f); ((Graphic)obj16).raycastTarget = false; _sizeFillRect = obj15; _sizeBarMaxWidth = num6 - 8f; float num8 = num7 + num6 + 8f; RectTransform obj17 = CreateRect((Transform)(object)_content, "SizePlus", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num8, num3), new Vector2(28f, 28f)); Image targetGraphic4 = AddPanelSprite(((Component)obj17).gameObject, ButtonTint); Button obj18 = ((Component)obj17).gameObject.AddComponent<Button>(); ((Selectable)obj18).targetGraphic = (Graphic)(object)targetGraphic4; ButtonClickedEvent onClick5 = obj18.onClick; object obj19 = <>c.<>9__23_2; if (obj19 == null) { UnityAction val8 = delegate { ChangeSize(1f); }; <>c.<>9__23_2 = val8; obj19 = (object)val8; } ((UnityEvent)onClick5).AddListener((UnityAction)obj19); BuildBar(obj17, 14f, 3f, 0f); BuildBar(obj17, 3f, 14f, 0f); num3 -= 38f; RectTransform obj20 = CreateRect((Transform)(object)_content, "ClearAllButton", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(12f, num3), new Vector2(num - 24f, 26f)); Image targetGraphic5 = AddPanelSprite(((Component)obj20).gameObject, new Color(0.75f, 0.2f, 0.15f, 0.85f)); Button obj21 = ((Component)obj20).gameObject.AddComponent<Button>(); ((Selectable)obj21).targetGraphic = (Graphic)(object)targetGraphic5; ButtonClickedEvent onClick6 = obj21.onClick; object obj22 = <>O.<2>__ClearAll; if (obj22 == null) { UnityAction val9 = ClearAll; <>O.<2>__ClearAll = val9; obj22 = (object)val9; } ((UnityEvent)onClick6).AddListener((UnityAction)obj22); CreateLabel(obj20, "Очистить всё", Color.white, 13f); RefreshVisuals(); ConfirmDialog.Build(mm.m_largeRoot.transform, _font); UiAssetDump.DumpOnce(mm); } private static Image AddPanelSprite(GameObject go, Color tint) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) Image val = go.AddComponent<Image>(); Sprite itemBackground = ValheimUiSprites.ItemBackground; if ((Object)(object)itemBackground != (Object)null) { val.sprite = itemBackground; val.type = (Type)1; } ((Graphic)val).color = tint; return val; } private static Image AddSelectionFrame(RectTransform parent) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) RectTransform val = CreateRect((Transform)(object)parent, "Selected", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, parent.sizeDelta + new Vector2(6f, 6f)); Image val2 = ((Component)val).gameObject.AddComponent<Image>(); Sprite selectionFrame = ValheimUiSprites.SelectionFrame; if ((Object)(object)selectionFrame != (Object)null) { val2.sprite = selectionFrame; val2.type = (Type)1; } ((Graphic)val2).color = SelectionTint; ((Graphic)val2).raycastTarget = false; ((Component)val).gameObject.SetActive(false); return val2; } private static void ToggleCollapsed() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) _collapsed = !_collapsed; ((Component)_content).gameObject.SetActive(!_collapsed); _panel.sizeDelta = (Vector2)(_collapsed ? new Vector2(38f, 38f) : _expandedSize); if ((Object)(object)_collapseGlyph != (Object)null) { ((TMP_Text)_collapseGlyph).text = (_collapsed ? "+" : "–"); } if (_collapsed) { MapDrawingController.CurrentTool = Tool.None; } } private static void SetTool(Tool tool) { MapDrawingController.CurrentTool = ((MapDrawingController.CurrentTool != tool) ? tool : Tool.None); RefreshVisuals(); } private static void SelectColor(DrawColorOption option) { MapRoutesPlugin.DrawColor.Value = option; MapDrawingController.CurrentTool = Tool.Draw; RefreshVisuals(); } private static void ChangeSize(float direction) { MapRoutesPlugin.LineThickness.Value = Mathf.Clamp(MapRoutesPlugin.LineThickness.Value + direction, 1f, 14f); RefreshVisuals(); } private static void ClearAll() { ConfirmDialog.Show(delegate { MapDrawingController.Instance?.RequestClearAll(); }); } private static void ToggleVisibility() { MapDrawingController.ShowDrawings = !MapDrawingController.ShowDrawings; RefreshVisuals(); } private static void RefreshVisuals() { //IL_00bb: 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_00de: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_visibilityCheckmark != (Object)null) { ((Component)_visibilityCheckmark).gameObject.SetActive(MapDrawingController.ShowDrawings); } if ((Object)(object)_eraserSelection != (Object)null) { ((Component)_eraserSelection).gameObject.SetActive(MapDrawingController.CurrentTool == Tool.Erase); } if (_colorSelections != null) { for (int i = 0; i < Palette.Length; i++) { bool active = MapDrawingController.CurrentTool == Tool.Draw && Palette[i] == MapRoutesPlugin.DrawColor.Value; ((Component)_colorSelections[i]).gameObject.SetActive(active); } } if ((Object)(object)_sizeFillRect != (Object)null) { float num = Mathf.InverseLerp(1f, 14f, MapRoutesPlugin.LineThickness.Value); Vector2 sizeDelta = _sizeFillRect.sizeDelta; sizeDelta.x = Mathf.Max(4f, _sizeBarMaxWidth * num); _sizeFillRect.sizeDelta = sizeDelta; } } private static void BuildCrossIcon(RectTransform parent) { BuildBar(parent, 18f, 3f, 45f); BuildBar(parent, 18f, 3f, -45f); } private static RectTransform BuildBar(RectTransform parent, float length, float thickness, float angle) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0066: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = CreateRect((Transform)(object)parent, "Bar", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(length, thickness)); ((Transform)obj).localRotation = Quaternion.Euler(0f, 0f, angle); Image obj2 = ((Component)obj).gameObject.AddComponent<Image>(); ((Graphic)obj2).color = Color.white; ((Graphic)obj2).raycastTarget = false; return obj; } private static TextMeshProUGUI CreateLabel(RectTransform parent, string text, Color color, float fontSize) { //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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI val = ((Component)CreateRect((Transform)(object)parent, "Label", Vector2.zero, Vector2.one, new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero)).gameObject.AddComponent<TextMeshProUGUI>(); if ((Object)(object)_font != (Object)null) { ((TMP_Text)val).font = _font; } ((TMP_Text)val).text = text; ((TMP_Text)val).fontSize = fontSize; ((Graphic)val).color = color; ((TMP_Text)val).alignment = (TextAlignmentOptions)514; ((Graphic)val).raycastTarget = false; return val; } private static RectTransform CreateRect(Transform parent, string name, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 anchoredPos, Vector2 size) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = anchorMin; val2.anchorMax = anchorMax; val2.pivot = pivot; val2.anchoredPosition = anchoredPos; val2.sizeDelta = size; return val2; } } [HarmonyPatch(typeof(Minimap), "Awake")] internal static class Minimap_Awake_AddToolbar { private static void Postfix(Minimap __instance) { ToolbarUI.Build(__instance); } } internal static class UiAssetDump { private static bool _done; internal static void DumpOnce(Minimap mm) { //IL_0095: 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_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_018e: 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_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) if (_done) { return; } _done = true; try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("=== MapRoutes UI asset dump ==="); Image[] componentsInChildren = mm.m_largeRoot.GetComponentsInChildren<Image>(true); foreach (Image val in componentsInChildren) { stringBuilder.AppendLine("[Image] " + BuildPath(((Component)val).transform) + " | sprite=" + (((Object)(object)val.sprite != (Object)null) ? ((Object)val.sprite).name : "null") + " " + $"| type={val.type} | color={((Graphic)val).color}"); } RawImage[] componentsInChildren2 = mm.m_largeRoot.GetComponentsInChildren<RawImage>(true); foreach (RawImage val2 in componentsInChildren2) { stringBuilder.AppendLine("[RawImage] " + BuildPath(((Component)val2).transform) + " | texture=" + (((Object)(object)val2.texture != (Object)null) ? ((Object)val2.texture).name : "null")); } TMP_Text[] componentsInChildren3 = mm.m_largeRoot.GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val3 in componentsInChildren3) { RectTransform rectTransform = val3.rectTransform; stringBuilder.AppendLine($"[Text] {BuildPath(val3.transform)} | text=\"{val3.text}\" | anchoredPos={rectTransform.anchoredPosition} " + $"| sizeDelta={rectTransform.sizeDelta} | anchorMin={rectTransform.anchorMin} | anchorMax={rectTransform.anchorMax}"); } Button[] componentsInChildren4 = mm.m_largeRoot.GetComponentsInChildren<Button>(true); foreach (Button val4 in componentsInChildren4) { Graphic targetGraphic = ((Selectable)val4).targetGraphic; Image val5 = (Image)(object)((targetGraphic is Image) ? targetGraphic : null); string[] obj = new string[6] { "[Button] ", BuildPath(((Component)val4).transform), " | targetSprite=", ((Object)(object)val5 != (Object)null && (Object)(object)val5.sprite != (Object)null) ? ((Object)val5.sprite).name : "null", " | pressedSprite=", null }; SpriteState spriteState = ((Selectable)val4).spriteState; object obj2; if (!((Object)(object)((SpriteState)(ref spriteState)).pressedSprite != (Object)null)) { obj2 = "null"; } else { spriteState = ((Selectable)val4).spriteState; obj2 = ((Object)((SpriteState)(ref spriteState)).pressedSprite).name; } obj[5] = (string)obj2; stringBuilder.AppendLine(string.Concat(obj)); } string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ".", "ui_dump.txt"); File.WriteAllText(text, stringBuilder.ToString(), Encoding.UTF8); MapRoutesPlugin.LogStatic("UI dump written to " + text); } catch (Exception ex) { MapRoutesPlugin.LogStatic("UI dump failed: " + ex); } } private static string BuildPath(Transform t) { List<string> list = new List<string>(); while ((Object)(object)t != (Object)null) { list.Add(((Object)t).name); t = t.parent; } list.Reverse(); return string.Join("/", list); } } internal static class ValheimUiSprites { private static readonly Dictionary<string, Sprite> Cache = new Dictionary<string, Sprite>(); private static bool _scanned; private static readonly string[] Names = new string[4] { "item_background", "selection_frame", "checkbox", "checkbox_marker_filtered" }; internal static Sprite ItemBackground => Get("item_background"); internal static Sprite SelectionFrame => Get("selection_frame"); internal static Sprite Checkbox => Get("checkbox"); internal static Sprite CheckboxMark => Get("checkbox_marker_filtered"); private static Sprite Get(string name) { EnsureScanned(); Cache.TryGetValue(name, out var value); return value; } private static void EnsureScanned() { if (_scanned) { return; } _scanned = true; Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>(); foreach (Sprite val in array) { string[] names = Names; foreach (string text in names) { if (((Object)val).name == text) { Cache[text] = val; break; } } } } } }