Decompiled source of MiniMapPlus v1.3.1

MIniMap.dll

Decompiled 4 hours ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
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: AssemblyTitle("MIniMap")]
[assembly: AssemblyDescription("Minimalistic Minimap mod for Lethal Company")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Diman3012")]
[assembly: AssemblyProduct("MIniMap")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4d061c1c-dea6-41cf-ac43-cd97a23e03fa")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace MIniMap;

[BepInPlugin("com.invertigo.minimapplus", "MiniMapPlus", "1.3.1")]
public class MinimalMinimap : BaseUnityPlugin
{
	public static MinimalMinimap Instance;

	public static MinimapData Data;

	public static PlayerControllerB CustomTarget;

	public static int CustomTargetIndex;

	public ConfigEntry<bool> ConfigEnabled;

	private Harmony harmony;

	private void Awake()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		Instance = this;
		Data = new MinimapData();
		ConfigEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the minimap");
		harmony = new Harmony("com.invertigo.minimapplus");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Minimal Minimap (MiniMapPlus) loaded successfully!");
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "com.invertigo.minimapplus";

	public const string PLUGIN_NAME = "MiniMapPlus";

	public const string PLUGIN_VERSION = "1.3.1";
}
public class MinimapData
{
	public int Size = 200;

	public float XOffset = -10f;

	public float YOffset = -10f;

	public float Zoom = 20f;

	public bool AutoRotate = true;

	public bool FreezeTarget = true;

	public KeyCode SwitchKey = (KeyCode)284;

	public KeyCode ToggleKey = (KeyCode)283;

	public KeyCode ZoomKey = (KeyCode)285;

	public float[] ZoomLevels = new float[3] { 60f, 40f, 20f };

	public int currentZoomIndex = 0;
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch
{
	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("com.invertigo.minimapplus Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(obj, GetHash("com.invertigo.minimapplus"));
		}
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
	}

	private static uint GetHash(string value)
	{
		return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class MinimapPatch
{
	private static GameObject minimapObject;

	private static RawImage minimapImage;

	public static Camera minimapCamera;

	public static RenderTexture minimapTexture;

	private static bool cameraInitialized;

	private static int framesSinceLanded;

	[HarmonyPatch("ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void CreateMinimap()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0049: 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_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)minimapObject != (Object)null))
		{
			minimapObject = new GameObject("MIniMap_UI");
			minimapImage = minimapObject.AddComponent<RawImage>();
			RectTransform rectTransform = ((Graphic)minimapImage).rectTransform;
			rectTransform.anchorMin = new Vector2(1f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(1f, 1f);
			rectTransform.sizeDelta = new Vector2((float)MinimalMinimap.Data.Size, (float)MinimalMinimap.Data.Size);
			rectTransform.anchoredPosition = new Vector2(MinimalMinimap.Data.XOffset, MinimalMinimap.Data.YOffset);
			InitializeCamera();
			minimapObject.transform.SetParent(((Component)HUDManager.Instance.playerScreenTexture).transform, false);
			bool value = MinimalMinimap.Instance.ConfigEnabled.Value;
			minimapObject.SetActive(value);
		}
	}

	private static void InitializeCamera()
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		if ((Object)(object)StartOfRound.Instance.mapScreen != (Object)null && (Object)(object)StartOfRound.Instance.mapScreen.cam != (Object)null)
		{
			if ((Object)(object)minimapCamera != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)minimapCamera).gameObject);
			}
			if ((Object)(object)minimapTexture != (Object)null)
			{
				minimapTexture.Release();
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)StartOfRound.Instance.mapScreen.cam).gameObject, ((Component)StartOfRound.Instance.mapScreen.cam).transform.parent);
			((Object)val).name = "MinimapCamera";
			val.SetActive(true);
			minimapCamera = val.GetComponent<Camera>();
			((Behaviour)minimapCamera).enabled = true;
			minimapTexture = new RenderTexture(480, 480, 24);
			((Object)minimapTexture).name = "MinimapRenderTexture";
			minimapTexture.Create();
			minimapCamera.targetTexture = minimapTexture;
			minimapImage.texture = (Texture)(object)minimapTexture;
		}
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void HandleHotkeys(PlayerControllerB __instance)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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)
		if (!((NetworkBehaviour)__instance).IsOwner || (Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController)
		{
			return;
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.ToggleKey) && !__instance.isTypingChat && !__instance.inTerminalMenu)
		{
			bool flag = !MinimalMinimap.Instance.ConfigEnabled.Value;
			MinimalMinimap.Instance.ConfigEnabled.Value = flag;
			if ((Object)(object)minimapObject != (Object)null)
			{
				minimapObject.SetActive(flag);
			}
		}
		if (!MinimalMinimap.Instance.ConfigEnabled.Value)
		{
			return;
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.SwitchKey) && !__instance.isTypingChat && !__instance.inTerminalMenu)
		{
			SwitchTarget();
			InitializeCamera();
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.ZoomKey) && !__instance.isTypingChat && !__instance.inTerminalMenu)
		{
			MinimalMinimap.Data.currentZoomIndex = (MinimalMinimap.Data.currentZoomIndex + 1) % MinimalMinimap.Data.ZoomLevels.Length;
			MinimalMinimap.Data.Zoom = MinimalMinimap.Data.ZoomLevels[MinimalMinimap.Data.currentZoomIndex];
		}
		if (__instance.isPlayerDead)
		{
			if (MinimalMinimap.Data.FreezeTarget)
			{
				MinimalMinimap.Data.FreezeTarget = false;
			}
			if ((Object)(object)__instance.spectatedPlayerScript != (Object)null)
			{
				SetMapTargetToPlayer(__instance.spectatedPlayerScript);
			}
		}
		else if (!MinimalMinimap.Data.FreezeTarget)
		{
			MinimalMinimap.Data.FreezeTarget = true;
			SetMapTargetToPlayer(__instance);
		}
		if ((Object)(object)MinimalMinimap.CustomTarget == (Object)null)
		{
			SetMapTargetToPlayer(__instance);
		}
		UpdateMinimapCamera();
	}

	private static void UpdateMinimapCamera()
	{
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: 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_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: 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)
		if ((Object)(object)minimapCamera == (Object)null && !cameraInitialized && (Object)(object)StartOfRound.Instance.mapScreen != (Object)null && (Object)(object)StartOfRound.Instance.mapScreen.cam != (Object)null && !StartOfRound.Instance.inShipPhase)
		{
			framesSinceLanded++;
			if (framesSinceLanded > 100 || ((Behaviour)StartOfRound.Instance.mapScreen.cam).enabled)
			{
				InitializeCamera();
				cameraInitialized = true;
			}
		}
		if ((Object)(object)minimapCamera == (Object)null || (Object)(object)MinimalMinimap.CustomTarget == (Object)null)
		{
			return;
		}
		if (StartOfRound.Instance.inShipPhase)
		{
			((Behaviour)minimapCamera).enabled = false;
			if ((Object)(object)minimapImage != (Object)null)
			{
				((Behaviour)minimapImage).enabled = false;
			}
			return;
		}
		if ((Object)(object)minimapImage != (Object)null)
		{
			((Behaviour)minimapImage).enabled = true;
		}
		((Component)minimapCamera).gameObject.SetActive(true);
		((Behaviour)minimapCamera).enabled = true;
		((Component)minimapCamera).transform.position = ((Component)MinimalMinimap.CustomTarget).transform.position + Vector3.up * 3.636f;
		if ((Object)(object)StartOfRound.Instance.mapScreen != (Object)null && (Object)(object)StartOfRound.Instance.mapScreen.cam != (Object)null)
		{
			minimapCamera.nearClipPlane = StartOfRound.Instance.mapScreen.cam.nearClipPlane;
			minimapCamera.farClipPlane = StartOfRound.Instance.mapScreen.cam.farClipPlane;
		}
		minimapCamera.orthographicSize = MinimalMinimap.Data.Zoom;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(90f, 0f, 0f);
		if (MinimalMinimap.Data.AutoRotate)
		{
			((Component)minimapCamera).transform.eulerAngles = new Vector3(val.x, ((Component)MinimalMinimap.CustomTarget).transform.eulerAngles.y, val.z);
		}
		else
		{
			((Component)minimapCamera).transform.eulerAngles = val;
		}
		TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i].mapRadarObject != (Object)null)
			{
				array[i].mapRadarObject.transform.eulerAngles = new Vector3(val.x, ((Component)minimapCamera).transform.eulerAngles.y, val.z);
			}
		}
	}

	private static void SetMapTargetToPlayer(PlayerControllerB target)
	{
		ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
		if ((Object)(object)mapScreen == (Object)null || (Object)(object)target == (Object)null || (Object)(object)MinimalMinimap.CustomTarget == (Object)(object)target)
		{
			return;
		}
		for (int i = 0; i < mapScreen.radarTargets.Count; i++)
		{
			TransformAndName val = mapScreen.radarTargets[i];
			if (val != null && (Object)(object)val.transform != (Object)null && (Object)(object)((Component)val.transform).GetComponent<PlayerControllerB>() == (Object)(object)target)
			{
				MinimalMinimap.CustomTargetIndex = i;
				MinimalMinimap.CustomTarget = target;
				break;
			}
		}
	}

	private static void SwitchTarget()
	{
		ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
		if ((Object)(object)mapScreen == (Object)null || mapScreen.radarTargets == null || mapScreen.radarTargets.Count == 0)
		{
			return;
		}
		int count = mapScreen.radarTargets.Count;
		int num = MinimalMinimap.CustomTargetIndex;
		for (int i = 0; i < count; i++)
		{
			num = (num + 1) % count;
			TransformAndName val = mapScreen.radarTargets[num];
			if (val != null && !((Object)(object)val.transform == (Object)null))
			{
				PlayerControllerB component = ((Component)val.transform).GetComponent<PlayerControllerB>();
				if (!((Object)(object)component == (Object)null) && (component.isPlayerControlled || component.isPlayerDead))
				{
					MinimalMinimap.CustomTargetIndex = num;
					MinimalMinimap.CustomTarget = component;
					break;
				}
			}
		}
	}
}