Decompiled source of MimesisMinimap v1.1.1

MimesisMinimap.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Preferences;
using Mimic.Actors;
using MyMimesisMinimap;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(MinimapMod), "2D風格雷達小地圖", "1.0.0", "YourName", null)]
[assembly: MelonGame("ReLUGames", "MIMESIS")]
[assembly: AssemblyTitle("類別庫 (.NET Framework)")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("類別庫 (.NET Framework)")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b0f16656-1c85-4dce-bf2a-58b23ecfe30a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MyMimesisMinimap;

public class MinimapMod : MelonMod
{
	private bool isVisible = true;

	private MelonPreferences_Category configCategory;

	private MelonPreferences_Entry<float> cameraHeightEntry;

	private MelonPreferences_Entry<float> mapSizeEntry;

	private MelonPreferences_Entry<float> orthoSizeEntry;

	private GameObject mapCanvasObj;

	private RectTransform bgRect;

	private Camera mapCamera;

	private RenderTexture mapTexture;

	private Dictionary<int, RectTransform> teammateDots = new Dictionary<int, RectTransform>();

	private Dictionary<int, RectTransform> enemyDots = new Dictionary<int, RectTransform>();

	public override void OnInitializeMelon()
	{
		configCategory = MelonPreferences.CreateCategory("MinimapSettings");
		cameraHeightEntry = configCategory.CreateEntry<float>("CameraHeight", 10f, "攝影機高度 (建議範圍 3-15)", (string)null, false, false, (ValueValidator)null, (string)null);
		mapSizeEntry = configCategory.CreateEntry<float>("MapSize", 250f, "小地圖介面大小 (建議範圍 150-400)", (string)null, false, false, (ValueValidator)null, (string)null);
		orthoSizeEntry = configCategory.CreateEntry<float>("OrthoSize", 50f, "地圖視野範圍 (建議範圍 20-100)", (string)null, false, false, (ValueValidator)null, (string)null);
		MelonLogger.Msg("2D風格雷達(全Config版)已載入,按 M 切換地圖!");
	}

	private void CreateModernUI()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Expected O, but got Unknown
		//IL_016a: 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_01a0: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Expected O, but got Unknown
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Expected O, but got Unknown
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		mapTexture = new RenderTexture(512, 512, 16, (RenderTextureFormat)7);
		mapTexture.Create();
		GameObject val = new GameObject("MinimapCamera");
		Object.DontDestroyOnLoad((Object)(object)val);
		mapCamera = val.AddComponent<Camera>();
		mapCamera.orthographic = true;
		mapCamera.orthographicSize = orthoSizeEntry.Value;
		mapCamera.clearFlags = (CameraClearFlags)2;
		mapCamera.backgroundColor = new Color(0f, 0f, 0f, 1f);
		mapCamera.cullingMask = -1;
		mapCamera.targetTexture = mapTexture;
		mapCamera.nearClipPlane = 1f;
		mapCamera.farClipPlane = 20f;
		mapCanvasObj = new GameObject("MyMinimapCanvas");
		Object.DontDestroyOnLoad((Object)(object)mapCanvasObj);
		Canvas val2 = mapCanvasObj.AddComponent<Canvas>();
		val2.renderMode = (RenderMode)0;
		val2.sortingOrder = 100;
		mapCanvasObj.AddComponent<CanvasScaler>();
		GameObject val3 = new GameObject("MinimapBG");
		val3.transform.SetParent(mapCanvasObj.transform, false);
		bgRect = val3.AddComponent<RectTransform>();
		bgRect.sizeDelta = new Vector2(mapSizeEntry.Value, mapSizeEntry.Value);
		bgRect.anchorMin = new Vector2(1f, 1f);
		bgRect.anchorMax = new Vector2(1f, 1f);
		bgRect.pivot = new Vector2(1f, 1f);
		bgRect.anchoredPosition = new Vector2(-20f, -20f);
		RawImage val4 = val3.AddComponent<RawImage>();
		val4.texture = (Texture)(object)mapTexture;
		Material val5 = new Material(Shader.Find("UI/Default"));
		val5.color = new Color(0f, 1f, 0f, 1f);
		((Graphic)val4).material = val5;
		GameObject val6 = new GameObject("PlayerDot");
		val6.transform.SetParent(val3.transform, false);
		RectTransform val7 = val6.AddComponent<RectTransform>();
		val7.sizeDelta = new Vector2(8f, 8f);
		val7.anchorMin = new Vector2(0.5f, 0.5f);
		val7.anchorMax = new Vector2(0.5f, 0.5f);
		val7.pivot = new Vector2(0.5f, 0.5f);
		val7.anchoredPosition = Vector2.zero;
		Image val8 = val6.AddComponent<Image>();
		((Graphic)val8).color = Color.white;
	}

	public override void OnLateUpdate()
	{
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: 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_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Invalid comparison between Unknown and I4
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		Keyboard current = Keyboard.current;
		if (current != null && ((ButtonControl)current.mKey).wasPressedThisFrame)
		{
			isVisible = !isVisible;
		}
		if ((Object)(object)mapCanvasObj == (Object)null)
		{
			CreateModernUI();
		}
		if ((Object)(object)bgRect != (Object)null && ((Component)bgRect).gameObject.activeSelf != isVisible)
		{
			((Component)bgRect).gameObject.SetActive(isVisible);
			((Behaviour)mapCamera).enabled = isVisible;
		}
		if (!isVisible)
		{
			return;
		}
		if ((Object)(object)mapCamera != (Object)null)
		{
			mapCamera.orthographicSize = orthoSizeEntry.Value;
		}
		if ((Object)(object)bgRect != (Object)null)
		{
			bgRect.sizeDelta = new Vector2(mapSizeEntry.Value, mapSizeEntry.Value);
		}
		ProtoActor[] array = Object.FindObjectsByType<ProtoActor>((FindObjectsSortMode)0);
		ProtoActor val = null;
		ProtoActor[] array2 = array;
		foreach (ProtoActor val2 in array2)
		{
			if (val2.AmIAvatar())
			{
				val = val2;
				break;
			}
		}
		if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null)
		{
			return;
		}
		Transform transform = ((Component)val).gameObject.transform;
		float num = Mathf.Clamp(cameraHeightEntry.Value, 3f, 15f);
		((Component)mapCamera).transform.position = new Vector3(transform.position.x, transform.position.y + num, transform.position.z);
		((Component)mapCamera).transform.rotation = Quaternion.Euler(90f, transform.eulerAngles.y, 0f);
		HashSet<int> hashSet = new HashSet<int>();
		HashSet<int> hashSet2 = new HashSet<int>();
		ProtoActor[] array3 = array;
		foreach (ProtoActor val3 in array3)
		{
			if (!val3.dead && !((Object)(object)((Component)val3).gameObject == (Object)null) && !val3.AmIAvatar())
			{
				int actorID = val3.ActorID;
				Vector3 position = ((Component)val3).gameObject.transform.position;
				if ((int)val3.ActorType == 1)
				{
					hashSet.Add(actorID);
					UpdateDynamicDot(actorID, position, transform, Color.cyan, 8f, teammateDots);
				}
				else
				{
					hashSet2.Add(actorID);
					UpdateDynamicDot(actorID, position, transform, Color.red, 8f, enemyDots);
				}
			}
		}
		RemoveInactiveDots(teammateDots, hashSet);
		RemoveInactiveDots(enemyDots, hashSet2);
	}

	private void UpdateDynamicDot(int id, Vector3 targetWorldPos, Transform playerTransform, Color dotColor, float dotSize, Dictionary<int, RectTransform> dict)
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_00b1: 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)
		if (!dict.ContainsKey(id))
		{
			GameObject val = new GameObject("Dot_" + id);
			val.transform.SetParent(((Component)bgRect).transform, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.sizeDelta = new Vector2(dotSize, dotSize);
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).color = dotColor;
			dict[id] = val2;
		}
		RectTransform val4 = dict[id];
		Vector3 val5 = playerTransform.InverseTransformPoint(targetWorldPos);
		float value = mapSizeEntry.Value;
		float value2 = orthoSizeEntry.Value;
		float num = value / 2f / value2;
		float num2 = val5.x * num;
		float num3 = val5.z * num;
		float num4 = value / 2f;
		if (Mathf.Abs(num2) > num4 || Mathf.Abs(num3) > num4)
		{
			if (((Component)val4).gameObject.activeSelf)
			{
				((Component)val4).gameObject.SetActive(false);
			}
			return;
		}
		if (!((Component)val4).gameObject.activeSelf)
		{
			((Component)val4).gameObject.SetActive(true);
		}
		val4.anchoredPosition = new Vector2(num2, num3);
	}

	private void RemoveInactiveDots(Dictionary<int, RectTransform> dict, HashSet<int> activeIds)
	{
		List<int> list = new List<int>();
		foreach (KeyValuePair<int, RectTransform> item in dict)
		{
			if (!activeIds.Contains(item.Key))
			{
				list.Add(item.Key);
			}
		}
		foreach (int item2 in list)
		{
			if ((Object)(object)dict[item2] != (Object)null && (Object)(object)((Component)dict[item2]).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)dict[item2]).gameObject);
			}
			dict.Remove(item2);
		}
	}
}